js delete the array elements known suffixes

Suppose there are n element array arr, now deleted for the index subscript element

There are two ways:

1.splice: delete, automated padding elements behind the front
arr.splice (index, 1);
examples: // arr = [ 'a' , 'b', 'c', 'd']

arr.splice (1, 1); // results arr = [ 'a', 'c', 'd'] (subscript 1 starts, delete 1)

supplement:

spice increase: arr.splice (1,0, 'str'); // results arr = [ 'a', 'str', 'b', 'c', 'd']

Alternatively spice: arr.splice (1,1, 'str'); // results arr = [ 'a', 'str', 'c', 'd']

Alternatively spice 2: arr.splice (1,2, 'str'); // results arr = [ 'a', 'str', 'd'] (that is: subscript 1 starts into a 2 " str ")

Delete a plurality of spice: arr.splice (1,2); // results arr = [ 'a', 'd']

2.delete: After removal, the indexing position element is undefined
Delete ARR [index];
// results arr = [ 'a', undefined , 'c', 'd']

Guess you like

Origin www.cnblogs.com/liuranRan/p/11084862.html