Answers for "javascript remove array by value"

282

Javascript remove array item by value

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
10

js remove from array by value

const index = array.indexOf(item);
if (index !== -1) array.splice(index, 1);
Posted by: Guest on March-30-2020
3

delete from array based on value javascript

var index = array.indexOf(item);
if (index !== -1) array.splice(index, 1);
Posted by: Guest on May-28-2020
2

js remove item from array by value

var arr = ['bill', 'is', 'not', 'lame'];

arr.splice(output_items.indexOf('not'), 1);

console.log(arr) //returns ['bill', 'is', 'lame']
Posted by: Guest on August-24-2020
0

remove a value to an array of javascript

var data = [1, 2, 3];

// remove a specific value
// splice(starting index, how many values to remove);
data.splice(1, 1);
// data = [1, 3];

// remove last element
data.pop();
// data = [1, 2];
Posted by: Guest on November-10-2019

Code answers related to "javascript remove array by value"

Code answers related to "Javascript"

Browse Popular Code Answers by Language