array remove multiple items 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 = ['zero', 'one', 'two', 'three'];ar.shift();
Example 3: js remove several elements from array
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); }}
Example 4: js remove several elements from array
var ar = [1, 2, 3, 4, 5, 6];ar.length = 4;