How to Remove Item From Array by Index in Javascript

Last Updated on April 19, 2024 by Roshan Parihar

To remove item from array by index in javascript, use the array.splice() function and pass two arguments to perform this task.

You can also use the filter() function to delete the element. Let’s find out with the examples given below.

Using splice() to Remove Item From Array in Javascript

If you want to remove item from array by index in javascript, you can use the array.splice() function. It takes two arguments in which the first is the index position. The second is the numeber items to delete from array from the specified index.

Example 1

Test it Live

The above example contains six elements. The index position is 2 and we know that the array element starts from index zero(0). So, the 2nd index position item is 21 to remove from the array.

Delete Using filter() Function

In addition to the above example, you can also use the filter() function. In this method, you have to first find the item present at the specified index. After that, you can delete the item with this function.

Example 2

Test it Live

The specified index position is 1 to remove the 2nd element from the array whic is 13.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.