Find the index with indexOf, then splice it out: const i = arr.indexOf(value); if (i !== -1) arr.splice(i, 1);. That changes the array in place. For a new array instead, use arr.toSpliced(i, 1), or arr.filter((x) => x !== value) to drop every match.
JavaScript arrays have no remove(value) method, so every answer is a combination of two questions: do you know the index or only the value, and should the original array change in place or stay as it is? splice mutates; toSpliced and filter return a new array and leave the original alone. The one thing never to use is delete, which section 5 explains. Each example runs on this page: hit Run, then edit the code and run it again.
1indexOf + splice (in place)Recommended
splice(start, deleteCount) removes deleteCount elements starting at start, shifts everything after them left, and returns the removed elements as an array. Pair it with indexOf, which returns the index of the first === match or -1, and you remove one item by value. If you already have the index, skip indexOf and call arr.splice(i, 1) directly.
Output
Prints [ 'banana' ], then [ 'apple', 'cherry', 'date' ], then -1 [ 'apple', 'cherry' ]. That last line is the bug hiding in the most copied answer on the internet: a negative start counts back from the end, so an unguarded splice(-1, 1) silently deletes date. Keep the i !== -1 check. indexOf also removes only the first match and cannot find NaN; for either case use filter (section 3) or findIndex with a predicate.
2toSpliced() (a new array, ES2023)
toSpliced takes the same arguments as splice but returns a copy with the change applied and never touches the original. It is the right tool for React or Redux state, function arguments you don't own, and any data another part of the program still holds a reference to. It has been in every engine since 2023; the older equivalent spreads two slices around the index.
Output
Prints [ 'apple', 'cherry', 'date' ], then the untouched original [ 'apple', 'banana', 'cherry', 'date' ], then the same three-item result from the slice version. The -1 guard is still needed: toSpliced(-1, 1) counts from the end exactly like splice. Unlike splice, it returns the new array, not the removed items.
3filter() (every match, or by condition)
filter keeps every element its callback returns true for and builds a new array from them. That makes it the answer to two neighbouring questions: remove all occurrences of a value, and remove items that match a condition, such as an object with a given id. Objects are compared by reference, so indexOf can't find { id: 2 }; a predicate can.
Output
Prints [ 'css', 'html' ], then [ { id: 1, name: 'Ada' }, { id: 3, name: 'Grace' } ], then 3. Mind the direction of the test: filter takes a keep condition, so "remove id 2" is written user.id !== 2. It always walks the whole array, which is O(n) and fine for almost everything; if you need the original array itself to shrink (other code holds a reference to it), reassign the result or use the backwards loop in section 6.
4Which should you use?
| Method | Mutates | Removes | Best for |
|---|---|---|---|
| arr.splice(arr.indexOf(v), 1) | Yes | First match | One item, in place (guard -1) |
| arr.toSpliced(i, 1) | No | One index | Immutable updates, shared data |
| arr.filter((x) => x !== v) | No | Every match | All occurrences, objects by property |
| arr.pop() / arr.shift() | Yes | Last / first | Stacks and queues |
| delete arr[i] | Yes | Nothing (leaves a hole) | Never, on arrays |
5delete vs splice
delete is an object operator: it removes a property. Array indexes are properties, so delete arr[1] runs without complaint, but it removes only the value and leaves the slot empty. Nothing shifts and length stays the same. The result is a sparse array, which iteration methods treat inconsistently.
Output
After delete, Node prints [ 'a', <1 empty item>, 'c' ] with a length of 3. Reading the hole gives undefined, but 1 in letters is false, and forEach skips it entirely (0 a, 2 c), while a for loop or for...of would visit it as undefined. splice gives the array you actually wanted: [ 'a', 'c' ] 2. Use delete on object properties, never on array elements.
6Removing items inside a loop
Splicing while you walk forward is the classic way to miss elements. Every removal shifts the rest of the array one place left, so the element after the one you removed lands on the current index, and the loop's i++ steps right past it. Two neighbouring matches are enough to trigger it.
Output
The forward loop prints [ 1, 2, 3, 4 ]: one 2 survived because it slid into the slot the loop had just checked. Walking backwards prints [ 1, 3, 4 ], and so does filter. Prefer filter: each splice is itself an O(n) shift, so removing many items one splice at a time is O(n²), while filter is a single pass. Keep the backwards loop for when the same array object really must shrink in place.
Frequently asked questions
How do I remove a specific item from an array in JavaScript?
Find its index and splice it out: const i = arr.indexOf(item); if (i !== -1) arr.splice(i, 1);. That removes the first match in place. If you want a new array instead, use arr.toSpliced(i, 1) for one index or arr.filter((x) => x !== item) to remove every match.
Why does splice remove the last element when the item is not found?
indexOf returns -1 for a missing value, and splice treats a negative start as an offset from the end, so arr.splice(-1, 1) removes the last element. Always check i !== -1 before splicing. toSpliced behaves the same way.
What is the difference between delete and splice on an array?
delete arr[i] removes the value but leaves an empty slot: the length does not change, later elements do not move, and methods like forEach skip the hole. arr.splice(i, 1) removes the element, shifts the rest left and shortens the array. Use splice (or toSpliced/filter) on arrays and keep delete for object properties.
How do I remove an object from an array by its id?
Objects are compared by reference, so indexOf will not match a lookalike object. For a new array, use users.filter((u) => u.id !== id). To remove it in place, find the index with a predicate and splice: const i = users.findIndex((u) => u.id === id); if (i !== -1) users.splice(i, 1);.
How do I remove the first or last item of an array?
arr.pop() removes and returns the last element and arr.shift() removes and returns the first, both in place. Without mutating, arr.slice(0, -1) drops the last and arr.slice(1) drops the first. shift has to move every remaining element, so it is O(n) on large arrays.
Does filter or toSpliced change the original array?
No. Both return a new array and leave the original untouched, which is why they are the usual choice for React and Redux state. splice, pop, shift and delete all modify the array you call them on, and so does anything else holding a reference to it.
Run it yourself
Open any of these in the full JavaScript editor — tweak, run, and share.
JavaScript playground