I did an exercise recently and used Array.slice() and Array.splice(). I didn’t pay attention to the return value type before.
Array.slice() returns an Array -- an array consisting of a certain range of elements in the original array. array.
Array.splice() returns Array -- an array containing the elements removed from the original array.
What is returned is an array. Use typeof() to see that it is object. This is correct! What you need to remind you is:
When the array elements are numbers, use Array.slice() and Array.splice() To compare the size of one of the elements, please note that the
type must be converted. This is very hidden and it is difficult to check after an error. The
object type cannot be directly converted to number using Number(). You need to String first. ()/8@$
For example:
var arr = [0, 1, 2];
var arr1 = [1, 2, 3];
for (var i = 0; i trace (arr.slice (i,i 1) "--" typeof (arr.slice (i,i 1)));
//output- -0--object.....
trace (arr1.slice (i,i 1) "--" typeof (arr1.slice (i,i 1)));
//output-- 1--object....
trace (arr.slice (i,i 1)
trace (arr.slice (i,i 1)>arr1.slice (i,i 1));
//output--false,,,,object is not comparable size
trace (Number (arr.slice (i,i 1))
trace (Number(arr.slice (i,i 1).toString())
}
trace (arr.slice (i,i 1)
is written as
trace (arr.slice (i,i 1)[0]
Also