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"]
๐ŸŒ
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?

๐ŸŒ
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.
๐ŸŒ
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
... 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 the item to be removed by its index, you can use the delete operator.
๐ŸŒ
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 - The shift method removes the first item of the array. It also returns the removed element. You can remove the element at any index by using the splice method.
๐ŸŒ
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 - If you need to remove an object from an array based on a condition: const array = [ { id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }, { id: 3, name: 'Charlie' } ]; const index = array.findIndex(item => item.id === 2); if (index !== -1) { ...
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.
๐ŸŒ
Seanmcp
seanmcp.com โ€บ articles โ€บ remove-an-item-at-a-given-index-in-javascript
Remove an item at a given index in JavaScript โ€“ seanmcp.com
August 5, 2020 - function removeAtWithFilter(array, index) { return array.filter((_, i) => i !== index); } Note: I'm using the _ to indicate a parameter that I don't intend to reference and a non-description i variable because index is already in scope.
๐ŸŒ
Thesoftwarelounge
thesoftwarelounge.com โ€บ how-to-remove-items-at-specific-index-in-javascript
How to Remove Item(s) at Specific Index(es) in JavaScript
April 20, 2023 - But what if the item is not unique? What if thereโ€™s multiple โ€œsnakeโ€ items and you just want to remove the first one? Then you can use Array.findIndex to first find the index and then either use the splice or slice method from before.
๐ŸŒ
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 โ€บ smpnjn โ€บ deleting-an-item-in-an-array-at-a-specific-index-3mif
Deleting an Item in an Array at a Specific Index - DEV Community
September 18, 2022 - Then, we use that number to splice out one element at that index using splice(itemIndex, 1). Now, ravioli is removed from our array! let arr1 = [ 'potato', 'banana', 'ravioli', 'carrot' ]; let itemIndex = arr1.indexOf('ravioli'); // Returns ...
๐ŸŒ
Fjolt
fjolt.com โ€บ article โ€บ javascript-how-to-delete-array-item-at-index
Deleting an Item in an Array at a Specific Index
Then, we use that number to splice out one element at that index using splice(itemIndex, 1). Now, ravioli is removed from our array! let arr1 = [ 'potato', 'banana', 'ravioli', 'carrot' ]; let itemIndex = arr1.indexOf('ravioli'); // Returns ...
๐ŸŒ
Fjolt
fjolt.com โ€บ article โ€บ javascript-remove-item-from-array
How to remove a specific item from an array
The original array will be mutated ยท Secondly, it uses two functions - first we get the indexOf the array item to be removed, and then we splice the array to remove that single item.
๐ŸŒ
Log4JavaScript
log4javascript.org โ€บ home โ€บ js-framework โ€บ javascript tutorial: exploring the splice() method
What Does Splice Do in JavaScript: Splice() Method
June 26, 2023 - The Splice method is a built-in method in JavaScript that allows developers to change the contents by adding, removing, and replacing elements. By specifying the index at which to start the modification and the number of elements to modify, ...
๐ŸŒ
Nematrian
nematrian.com โ€บ JavaScriptMethodArraySplice
HTML, CSS, JavaScript Tutorial
The splice() method (when applied to a JavaScript array) adds / removes elements to / from the array ยท It has the following syntax with the following parameters. It returns a new array containing the removed items, if any
๐ŸŒ
Learnjavascript
learnjavascript.co.uk โ€บ jsintermediate โ€บ arrays.html
JavaScript Arrays
// Create an array with four elements. var weekDays = ['Mon', 'Tues', 'Wed', 'Thurs']; /* Remove element 2 and 3 from the array using the splice() method. The first number within the brackets is the starting index to delete from, remember indexing starts from 0.
๐ŸŒ
Hippani
hippani.com
Arrays - JavaScript - Learn - Hippani
Arrays are used to store lists of variables. You can change an array using it's built in functions. var Fruit=new Array(); Fruit[0]="Apple"; Fruit[1]="Banana"; Fruit[2]="Orange"; alert("The second fruit is :"+Fruit[1]); var Veg=new Array("Potato" , "Carrot" , "Peas"); var EmptyArray=new Array(3); ...