Answers for "js remove specific element from array"

277

javascript array remove element

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"]
Posted by: Guest on July-19-2019
16

js array delete specific element

var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
var removed = arr.splice(2,2);
/*
removed === [3, 4]
arr === [1, 2, 5, 6, 7, 8, 9, 0]
*/
Posted by: Guest on September-23-2019
1

javascript remove a specific item from an array

let array = [1, 2, 6, 4, 5, 6, 7];

array = array.filter(element => element !== 6); // [1,2,4,5,7]
Posted by: Guest on June-12-2021
1

remove a specific element from an array

array.splice(array.indexOf(item), 1);
Posted by: Guest on November-12-2020
9

js remove specific element from array

const array = [2, 5, 9];

console.log(array);

const index = array.indexOf(5);
if (index > -1) {
  array.splice(index, 1);
}

// array = [2, 9]
console.log(array);
Posted by: Guest on June-15-2020
6

how to delete element in list javascript

//using filter method
let itemsToBeRemoved = ["Sunday", "Monday"]
var filteredArray = myArray.filter(item => !itemsToBeRemoved.includes(item))
Posted by: Guest on May-20-2020

Code answers related to "js remove specific element from array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language