Remove by value with filter()
const items = [1, 2, 3, 2];
const result = items.filter(x => x !== 2);
console.log(result); // [1, 3]
filter keeps every element that passes the test, so it removes all matches and leaves the original array unchanged.
Remove by index with splice()
const items = ["a", "b", "c"];
items.splice(1, 1);
console.log(items); // ["a", "c"]
splice(index, count) deletes count items starting at index. Note that it changes the array in place.
Find the index first, then remove it
const i = items.indexOf("c");
if (i !== -1) items.splice(i, 1);
Use indexOf to locate a value, check it is not -1, then splice it out.
Remove from the start or end
items.pop(); // removes the last item
items.shift(); // removes the first item
Which method should you use?
- filter() — when you want a new array and to remove every match.
- splice() — when you know the index and want to edit in place.
- pop / shift — for the last or first element.
Frequently asked questions
Does filter change the original array?
No. filter always returns a brand-new array and leaves the original alone, which makes it safer for predictable code.
Why does delete leave a hole?
The delete operator removes the value but keeps the slot, leaving undefined behind. Use splice or filter to remove the element completely.
Master array methods step by step in our free JavaScript course.