remove 2 items from array javascript code example
Example 1: javascript removing items looping through array
var colors=["red","green","blue","yellow"];
for (var i = colors.length - 1; i >= 0; i--) {
if (colors[i] === "green" || colors[i] === "blue") {
colors.splice(i, 1);
}
}
Example 2: js remove several elements from array
var ar = [1, 2, 3, 4, 5, 6];ar.pop();
Example 3: js remove several elements from array
var array = [1, 2, 3, 4];var evens = _.remove(array, function(n) { return n % 2 === 0;});console.log(array);
Example 4: js remove several elements from array
var ar = [1, 2, 3, 4, 5, 6];ar.length = 4;