Remove an item from an array in JavaScript

javascript

Updated August 29, 2026

Use filter() when you want a new array without matching items:

const numbers = [1, 2, 3, 2];
const withoutTwos = numbers.filter(number => number !== 2);

Use splice() when you know the index and intentionally want to mutate the existing array:

const items = ['a', 'b', 'c'];
const index = items.indexOf('b');
if (index !== -1) items.splice(index, 1);

filter() removes every item that fails the predicate. splice() removes a specific count and shifts later indexes. Do not use delete items[index]; it leaves a hole in the array. For objects, compare a stable identifier rather than object identity when the item came from another array or API response. Choose mutation or a new value consistently with the state-management system your application uses.

Sources

related.

Ruslan Osipov

Ruslan Osipov

About the author