Find the index of the array element you want to remove using indexOf, and then remove that index with splice.

The splice() method changes the contents of an array by removing existing elements and/or adding new elements.

const array = [2, 5, 9];

console.log(array);

const index = array.indexOf(5);
if (index > -1) { // only splice array when item is found
  array.splice(index, 1); // 2nd parameter means remove one item only
}

// array = [2, 9]
console.log(array);

The second parameter of splice is the number of elements to remove. Note that splice modifies the array in place and returns a new array containing the elements that have been removed.


For completeness, here are functions. The first function removes only a single occurrence (e.g., removing the first match of 5 from [2,5,9,1,5,8,5]), while the second function removes all occurrences:

function removeItemOnce(arr, value) {
  var index = arr.indexOf(value);
  if (index > -1) {
    arr.splice(index, 1);
  }
  return arr;
}

function removeItemAll(arr, value) {
  var i = 0;
  while (i < arr.length) {
    if (arr[i] === value) {
      arr.splice(i, 1);
    } else {
      ++i;
    }
  }
  return arr;
}
// Usage
console.log(removeItemOnce([2,5,9,1,5,8,5], 5))
console.log(removeItemAll([2,5,9,1,5,8,5], 5))

In TypeScript, these functions can stay type-safe with a type parameter:

function removeItem<T>(arr: Array<T>, value: T): Array<T> {
  const index = arr.indexOf(value);
  if (index > -1) {
    arr.splice(index, 1);
  }
  return arr;
}
Top answer
1 of 16
17015

Find the index of the array element you want to remove using indexOf, and then remove that index with splice.

The splice() method changes the contents of an array by removing existing elements and/or adding new elements.

const array = [2, 5, 9];

console.log(array);

const index = array.indexOf(5);
if (index > -1) { // only splice array when item is found
  array.splice(index, 1); // 2nd parameter means remove one item only
}

// array = [2, 9]
console.log(array);

The second parameter of splice is the number of elements to remove. Note that splice modifies the array in place and returns a new array containing the elements that have been removed.


For completeness, here are functions. The first function removes only a single occurrence (e.g., removing the first match of 5 from [2,5,9,1,5,8,5]), while the second function removes all occurrences:

function removeItemOnce(arr, value) {
  var index = arr.indexOf(value);
  if (index > -1) {
    arr.splice(index, 1);
  }
  return arr;
}

function removeItemAll(arr, value) {
  var i = 0;
  while (i < arr.length) {
    if (arr[i] === value) {
      arr.splice(i, 1);
    } else {
      ++i;
    }
  }
  return arr;
}
// Usage
console.log(removeItemOnce([2,5,9,1,5,8,5], 5))
console.log(removeItemAll([2,5,9,1,5,8,5], 5))

In TypeScript, these functions can stay type-safe with a type parameter:

function removeItem<T>(arr: Array<T>, value: T): Array<T> {
  const index = arr.indexOf(value);
  if (index > -1) {
    arr.splice(index, 1);
  }
  return arr;
}
2 of 16
2617
  • Do it simple, intuitive and explicit (Occam's razor)
  • Do it immutable (original array stays unchanged)
  • Do it with standard JavaScript functions, if your browser doesn't support them - use polyfill

In this code example I use array.filter(...) function to remove unwanted items from an array. This function doesn't change the original array and creates a new one. If your browser doesn't support this function (e.g. Internet Explorer before version 9, or Firefox before version 1.5), consider polyfilling with core-js.

Be mindful though, creating a new array every time takes a big performance hit. If the list is very large (think 10k+ items) then consider using other methods.

Removing item (ECMA-262 Edition 5 code AKA old style JavaScript)

var value = 3

var arr = [1, 2, 3, 4, 5, 3]

arr = arr.filter(function(item) {
    return item !== value
})

console.log(arr)
// [ 1, 2, 4, 5 ]

Removing item (ECMAScript 6 code)

let value = 3

let arr = [1, 2, 3, 4, 5, 3]

arr = arr.filter(item => item !== value)

console.log(arr)
// [ 1, 2, 4, 5 ]

IMPORTANT ECMAScript 6 () => {} arrow function syntax is not supported in Internet Explorer at all, Chrome before version 45, Firefox before version 22, and Safari before version 10. To use ECMAScript 6 syntax in old browsers you can use BabelJS.


Removing multiple items (ECMAScript 7 code)

An additional advantage of this method is that you can remove multiple items

let forDeletion = [2, 3, 5]

let arr = [1, 2, 3, 4, 5, 3]

arr = arr.filter(item => !forDeletion.includes(item))
// !!! Read below about array.includes(...) support !!!

console.log(arr)
// [ 1, 4 ]

IMPORTANT array.includes(...) function is not supported in Internet Explorer at all, Chrome before version 47, Firefox before version 43, Safari before version 9, and Edge before version 14 but you can polyfill with core-js.

Removing multiple items (in the future, maybe)

If the "This-Binding Syntax" proposal is ever accepted, you'll be able to do this:

// array-lib.js

export function remove(...forDeletion) {
    return this.filter(item => !forDeletion.includes(item))
}

// main.js

import { remove } from './array-lib.js'

let arr = [1, 2, 3, 4, 5, 3]

// :: This-Binding Syntax Proposal
// using "remove" function as "virtual method"
// without extending Array.prototype
arr = arr::remove(2, 3, 5)

console.log(arr)
// [ 1, 4 ]

Try it yourself in BabelJS :)

Reference

  • Array.prototype.includes
  • Functional composition
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Array โ€บ splice
Array.prototype.splice() - JavaScript | MDN
The splice() method of Array instances changes the contents of an array by removing or replacing existing elements and/or adding new elements in place. To create a new array with a segment removed and/or replaced without mutating the original array, use toSpliced(). To access part of an array without modifying it, see slice(). const months = ["Jan", "March", "April", "June"]; months.splice(1, 0, "Feb"); // Inserts at index 1 console.log(months); // Expected output: Array ["Jan", "Feb", "March", "April", "June"] months.splice(4, 1, "May"); // Replaces 1 element at index 4 console.log(months); // Expected output: Array ["Jan", "Feb", "March", "April", "May"]
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ how-to-remove-an-element-from-a-javascript-array-removing-a-specific-item-in-js
How to Remove an Element from a JavaScript Array โ€“ Removing a Specific Item in JS
August 31, 2022 - You can create more complex conditions than this example, as complex as you need. A final method to remove an element from an array without mutating the original array is by using the push method.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnprogramming โ€บ why is removing a specific element from an array so needlessly complicated in javascript?
r/learnprogramming on Reddit: Why is removing a specific element from an array so needlessly complicated in Javascript?
January 17, 2023 -

I'm just looking for something along the lines of:

array.remove("element")

Upon Googling for solutions so far I've found

Remove an element at any index with splice

Remove an element from an array with a for loop and push

Remove an element at any position of an array with slice and concat

There's more but I'm assuming you get the point. Why is this seemingly simple task so ridiculously complicated with Javascript?

Did nobody think to include a ".remove()" method when they were first developing Javascript? Is there a quirk of the language that makes it impossible? What is the reason for this?

๐ŸŒ
Sentry
sentry.io โ€บ sentry answers โ€บ javascript โ€บ how can i remove a specific item from an array?
How Can I Remove a Specific Item from an Array? | Sentry
The shift() method removes and returns the first element of an array. ... const myArray = [1, 2, 3, 4, 5]; const x = myArray.shift(); console.log(`myArray values: ${myArray}`); console.log(`variable x value: ${x}`); ... If you are identifying ...
๐ŸŒ
CoreUI
coreui.io โ€บ blog โ€บ how-to-remove-element-from-javascript-array
How to Remove Elements from a JavaScript Array ยท CoreUI
February 13, 2025 - One of the most popular ways to remove elements from an array in JavaScript is the splice method. This method modifies the original array directly. It takes at least two arguments (the start index and the number of elements to remove).
๐ŸŒ
DEV Community
dev.to โ€บ jsdevspace โ€บ 9-ways-to-remove-elements-from-arrays-in-javascript-4be6
9 Ways to Remove Elements from Arrays in JavaScript - DEV Community
August 6, 2024 - You can use the spread operator along with slice() or filter() to create a new array without a specific element. const colors = ['blue', 'red', 'yellow', 'green']; const indexToRemove = 2; // The spread operator ... combines these two slices ...
Find elsewhere
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_array_methods.asp
JavaScript Array Methods
The shift() method removes the first array element and "shifts" all other elements to a lower index.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ how-to-remove-a-specific-item-from-an-array-in-javascript
How to Remove a Specific Item from an Array in JavaScript ? - GeeksforGeeks
July 23, 2025 - Given an Array, the task is remove specific item from an array in JavaScript. It means we have an array with N items, and remove a particular item from array. ... The Array splice() method is used to remove an item from the array by its index.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ remove-elements-from-a-javascript-array
Remove Elements From a JavaScript Array | GeeksforGeeks
April 16, 2025 - The splice() method returns an array containing the removed element (["Banana"]), which is stored in the rEle variable. The updated array (["Apple", "Orange", "Mango"]) is then printed without the removed element.
๐ŸŒ
CoreUI
coreui.io โ€บ answers โ€บ how-to-remove-a-specific-item-from-an-array-in-javascript
How to remove a specific item from an array in JavaScript ยท CoreUI
September 18, 2025 - Use splice() with indexOf() to efficiently remove a specific element from a JavaScript array by value or index.
๐ŸŒ
Tutorial Republic
tutorialrepublic.com โ€บ faq โ€บ how-to-remove-a-specific-item-from-an-array-in-javascript.php
How to Remove a Specific Item from an Array in JavaScript
Here, the startIndex parameter specify the index at which to start splicing the array, it is required; the second parameter deleteCount is the number of elements to remove (if it is set to 0 no element will be removed).
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ how-to-remove-an-element-from-an-array-in-javascript
JavaScript - How to Remove an Element from an Array? - GeeksforGeeks
July 11, 2025 - Use the Delete Operator to remove elements from a JavaScript array. ... // Declare and initialize an array let array = ["lodash", "remove", "delete", "reset"] // Delete element at index 2 let deleted = delete array[2]; console.log("Removed: ...
๐ŸŒ
Medium
medium.com โ€บ @bosti โ€บ remove-a-specific-item-from-an-array-in-javascript-bfe45cdd5894
Remove a specific item from an array in JavaScript | by Bostiman | Medium
April 14, 2023 - const array = [1, 2, 3, 4, 5]; ...(newArray); // [1, 2, 4, 5] Another way to remove an element from an array is by mutating the original array....
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ remove-element-from-an-array-in-javascript
Remove Element from an Array in JavaScript
August 7, 2023 - If your project requires you to support old versions of Internet Explorer, specifically IE 8 in this case, then the indexOf() method will not work for you since it isn't supported in this version of IE. To deal with this, one solution is to shim the method, as shown in this Stack Overflow answer: ...
๐ŸŒ
Medium
zaferayan.medium.com โ€บ how-to-remove-a-specified-item-from-the-object-array-in-javascript-2f480beb2ef7
How to remove a specified item from the object array in JavaScript? | by Zafer Ayan | Medium
March 2, 2022 - There is a pop() function that exists but it only removes items from the end of an array. The old but gold splice method can remove items from the specified index. We can use it like fruits.splice(itemIndex, 1) to remove an item in that index.
๐ŸŒ
DEV Community
dev.to โ€บ sharmaprash โ€บ how-can-i-remove-a-specific-item-from-an-array-in-javascript-52j3
How can I remove a specific item from an array in JavaScript? - DEV Community
September 7, 2024 - Here are some common approaches: The filter() method creates a new array that excludes the specific item. const array = [1, 2, 3, 4, 5]; const itemToRemove = 3; const newArray = array.filter(item => item !== itemToRemove); console.log(newArray); ...