Remove an item from an array

The splice method allows us to remove one or more items from an array by defining a starting index and and a count splice(index, count). Thereby it mutates the original array and changes the original length.

Syntax

let arr = ['a','b','c','d','e'];
arr.splice(2, 1)
// ['a','b','d','e']

We can achieve the same result without mutating the original array, by creating a new one using the filter method on our original array like this

let arr = ['a','b','c','d','e'];
let newArray = arr.filter((item, index) => !( index === 2 ));
// ['a','b','d','e']
JavaScript