remove multiple 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: remove multiple values from array javascript
const nums = [1, 2, 3, 4, 5, 6];
const remove = [1, 2, 4, 6];
function removeFromArray(original, remove) {
return original.filter(value => !remove.includes(value));
}
Example 3: js remove several elements from array
var ar = ['zero', 'one', 'two', 'three'];ar.shift();
Example 4: remove all mutliple items from array javascript
arr = [2, 2, 2, 1, 3, 3, 3,3, 4, 5];
arr = arr.sort().filter((item,i)=>!(arr[i] == arr[i+1] || arr[i-1]==arr[i]));
console.log(arr);
Example 5: js remove several elements from array
var ar = [1, 2, 3, 4, 5, 6];ar.pop();