Array. slice () and Array. splice () Return Value Type _ basic knowledge
Source: Internet
Author: User
Array. slice () and Array. splice () return value types recently used in an exercise. Array. slice () and Array. splice ().
Array. slice () returns Array-an Array consisting of elements in a certain range in the original Array.
Array. splice () returns Array-an Array containing elements deleted from the original Array.
The returned result is an array. You can use typeof () to check whether it is an object. That's right! We need to remind you that:
When the Array element is a number, use Array. slice () and Array. splice () to compare the size of an element. Note that the value must be converted.
Type, which is hidden and difficult to query after an error occurs.
The object type cannot be directly converted to a Number using number (). toString ()/8 @ $
For example:
Var arr = [0, 1, 2];
Var arr1 = [1, 2, 3];
For (var I = 0; I <arr. length; 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) // output -- false, and object cannot be compared.
Trace (arr. slice (I, I + 1)> arr1.slice (I, I + 1 ));
// Output -- false, and object cannot be compared.
Trace (Number (arr. slice (I, I + 1 )) // Output -- undefined, and the object cannot be converted using Number ().
Trace (Number (arr. slice (I, I + 1). toString ()) // Output -- true, first toString () and then Number ()
}
Trace (arr. slice (I, I + 1) trace (arr. slice (I, I + 1)> arr1.slice (I, I + 1 ));
Write
Trace (arr. slice (I, I + 1) [0] trace (arr. slice (I, I + 1) [0]> arr1.slice (I, I + 1) [0]);
Yes.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.