JavaScript – Remove Element of Array by Index
To remove an element of an array at specific index in JavaScript, call splice() method on this array and pass the index and 1 (one element to remove) as arguments.
splice() method returns an array containing the removed element.
The syntax to remove an element of array arr
at index index
is
arr.splice(i, 1)
Example
In the following example, we have taken an array in arr
. We remove the element from this array present at index 2
using splice() method.
index.html
ADVERTISEMENT
Conclusion
In this JavaScript Tutorial, we learned how to remove an element from an array at specific index using splice() method.