Js array delete element by value

Code examples

217
0

remove a particular element from array

var colors = ["red","blue","car","green"];
var carIndex = colors.indexOf("car");//get  "car" index
//remove car from the colors array
colors.splice(carIndex, 1); // colors = ["red","blue","green"]
10
0

js remove from array by value

const index = array.indexOf(item);
if (index !== -1) array.splice(index, 1);
3
0

delete from array based on value javascript

var index = array.indexOf(item);
if (index !== -1) array.splice(index, 1);
0
0

remove item from array by value

var index = array.indexOf(item);
if (index !== -1) {
  array.splice(index, 1);
}
0
0

how can i remove a specific item from an array

const items = ['a', 'b', 'c', 'd', 'e', 'f']
const i = 2
const filteredItems = items.slice(0, i).concat(items.slice(i + 1, items.length))
// ["a", "b", "d", "e", "f"]

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................