javascript remove multiple items from array code example
Example 1: javascript remove multiple items from 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 array = [1, 2, 3, 4];var evens = _.remove(array, function(n) { return n % 2 === 0;});console.log(array);
Example 3: js remove several elements from array
var ar = [1, 2, 3, 4, 5, 6];ar.pop();
Example 4: js remove several elements from array
var arr1 = [1, 2, 3, 4, 5, 6];var arr2 = arr1;
Example 5: 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);