How to delete elements in an array using the element index number in JavaScript
This article mainly introduces how to delete the corresponding elements in an array by using the element index number in JavaScript. It involves the array operation technique in javascript and is very useful. For more information, see
This example describes how to delete elements in an array using the element index number in JavaScript. Share it with you for your reference. The specific analysis is as follows:
JavaScript deletes the elements in the array using the index number of the element. to delete the first element, use RemoveValByIndex (2). The JS array starts from 0.
?
| 1 2 3 4 5 6 7 8 9 10 11 |
Function RemoveValByIndex (arr, index ){ Arr. splice (index, 1 ); } Test = new Array (); Test [0] = 'apple '; Test [1] = 'ball '; Test [2] = 'cat '; Test [3] = 'Dog '; Alert ("Array before removing elements:" + test ); RemoveValByIndex (test, 2 ); Alert ("Array after removing elements:" + test ); |
I hope this article will help you design javascript programs.