JavaScript | How to delete any specific item from an array?

CodeyMaze
Mar 5, 2022

--

Array method pop() is used to delete the last element from an array. But what can we do if we have to delete any specific item from array.

Here are the ways by which we can remove any specific item from an array.

Array.splice()

In this method, we will first find the index of the element that needs to be deleted then we will make use of Array.splice() to delete the item.

Array.filter()

We can make use of Array.filter() to filter out only those items which we want. In this way we can remove unwanted item from leaving the original array intact.

--

--

CodeyMaze
CodeyMaze

Written by CodeyMaze

Crafting Solutions Through Code & Words https://codeymaze.com Feel free to follow me :)

No responses yet