0
Q:

js remove from array 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"]
97
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); 
12
const index = array.indexOf(item);
if (index !== -1) array.splice(index, 1);
8
var index = array.indexOf(item);
if (index !== -1) array.splice(index, 1);
2
var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
var filtered = array.filter(function(value, index, arr){
    return value > 5;
});
//filtered => [6, 7, 8, 9]
//array => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
9
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"]
-1
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];for( var i = 0; i < arr.length; i++){ if ( arr[i] === 5) { arr.splice(i, 1); }}//=> [1, 2, 3, 4, 6, 7, 8, 9, 0]
1
var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
var filtered = array.filter(function(value, index, arr){ 
  return value > 5;
});
//array => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
//filtered => [6, 7, 8, 9]
-1

New to Communities?

Join the community