recently encountered a puzzling problem when using the splice method. Don"t say too much about the code:
< script >
var arr=[1,2,3,7,8,9,2,6,9,9,8,5,2,3,1];
console.log("",arr);
arr.splice(undefined,1)
console.log("undefined",arr);
arr.splice(null,1)
console.log("null",arr);
arr.splice(NaN,1)
console.log("NaN",arr);
arr.splice(true,1)
console.log("true",arr);
arr.splice(false,1)
console.log("false",arr);
arr.splice(" ",1)
console.log("",arr);
arr.splice("",1)
console.log("",arr);
arr.splice(new Object(),1)
console.log("",arr);
arr.splice([],1)
console.log("",arr);
arr.splice(2.3,1)
console.log("",arr);
arr.splice(-2.3,1)
console.log("",arr);
arr.splice(-2,1)
console.log("",arr);
arr.splice(-2,1)
console.log("",arr);
</script>
the printed result is as follows;
I am a little dizzy at this time. The first parameter of the splice method is to specify the starting position of replacement or deletion, which is supposed to be an index value. For non-numeric parameters, if it calls a number object, undefined should be converted into NaN, and an error should be reported, but the printer still prints the result normally
all the above situations have one thing in common. It seems that only after they have been converted into the number 0 can the result of the printer be displayed.
do you have a boss to explain? I don"t think there is a description of this situation on MDN