On the use and difference of Delete () and splice () in the array method

Source: Internet
Author: User

Tag: color element false HTTP font position FFFFFF parameter ice

On the use and difference of Delete () and splice () in the array method

Deletearr[i] deletes the item of the specified index of the array, or the item will occupy the position of the original array when it is deleted, except that the value of the position becomes undefined; Delete also has a return value, which returns a value of True when it can be deleted. In addition, delete can delete a property of an object, but cannot delete the variable defined by VAR, at which time the return value is false;

var arr1 = [5, 4, 3, 2, 1, 9 ];    Console.log (arr1);     Delete arr1[1 ]);    Console.log (ARR1);

The results are printed as follows:

Two.splice (Index,length,[item]), the parentheses contain three parameters, index is the starting position of the indexes, length is required to delete the number of array elements, [item], for the deletion after the replacement of the elements, note that When only the delete operation is performed, the value of [item] is empty and can be not written at this time; The return value is the corresponding value of the deletion;

var arr1 = [5, 4, 3, 2, 1, 9 ];    Console.log (arr1);     0, 1 ));    Console.log (ARR1);
The results are printed as follows:

If you replace the deleted value with another:

On the use and difference of Delete () and splice () in the array method

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.