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);
const index = array.indexOf(item); if (index !== -1) array.splice(index, 1);
let value = 3 let arr = [1, 2, 3, 4, 5, 3] arr = arr.filter(item => item !== value) console.log(arr) // [ 1, 2, 4, 5 ]
var colors = ["red", "blue", "car","green"]; // op1: with direct arrow function colors = colors.filter(data => data != "car"); // op2: with function return value colors = colors.filter(function(data) { return data != "car"});
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]
const array = [2, 5, 9]; const index = array.indexOf(5); if (index > -1) { array.splice(index, 1); } // array = [2, 9]
var indexToRemove = 0; var numberToRemove = 1; arr.splice(indexToRemove, numberToRemove);