Remove Item from JavaScript Array

In earlier post, we have seen how to create array in JavaScript and various others built-in array methods. now we learn how to remove an item from JavaScript array.

There are different ways we can remove item from an array in JavaScript, let’s consider following different scenario.

  • Remove first item from JavaScript array
  • Remove last item from array
  • Remove items from a particular index position
  • Remove item once from array in JavaScript
  • Write custom method to remove an item depending on complex condition
different ways to remove item from array

First let's create an array , so we can experiment how differently we can remove items from array.

var teamA = new Array();

There are different built-in methods to remove an item from array.

shift method: remove first item from array

Shift method will remove the first item from the array.


Now if you see the below result, the first name “Sachin” has been removed from the list.

pop method: remove last item from array

Pop method will remove the last item from the array.


Notice, in below result, the last name “Lara” has been removed from the list.

splice method: remove item from array

We can use splice method in different ways.

Following splice method will remove all the items from array-index position 2, means only 0 and 1 will remain


Only first two name will remain, all are removed


Now, let’s call splice method differently, if we call teamA.splice(2,1), that will remove 1 item from second (2) index position.


See, the name “Dhoni” has been removed, which was in second index position, all are remaining.


Means teamA.splice(indexPosition, NoOfElements), if we don’t specify the number of elements to be removed, all elements will be removed after that index position.

delete item from array

We can use delete keyword to delete one element from array using the index number, that will delete the value and make the position empty.

delete teamA[4];

This will delete the item from 4th index position, means "Prasad" will be deleted, but there will be empty space.


Notice, the specified index value is deleted, but there is a space , ,

Custom method to remove item from array

Now, so far we have seen how to remove an item from array in javascript, where we know exactly which item to be deleted, and there is no where condition or multiple condition, that means delete call was straight and simple.

In real-time business scenario, sometimes we need to remove an item from array depending on some other input values, in such situation we need to write custom method, where after satisfying the condition we may call any of above methods to remove the item from array.

You may be interested in following posts:

JavaScript programming tutorials to learn JavaScript coding step by step, develop website using JavaScript and html.
Advanced JavaScript
Javascript Array Function Examples
javascript Interview Questions Answers
JavaScript Examples | JavaScript Online Course