JAVASCRIPT
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));
}
remove multiple items from array js
const removeFromArray = function (array, ...items) {
let remove = [...items];
return array.filter(value => !remove.includes(value));
remove multiple elements from array es6
const colors=["red","green","blue","yellow"];
let index = colors.length - 1;
while (index >= 0) {
if (['green', 'blue'].indexOf(colors[index]) > (-1)) {
colors.splice(index, 1);
}
index -= 1;
}
js remove several elements from array
var ar = ['zero', 'one', 'two', 'three'];ar.shift(); // returns "zero"console.log( ar ); // ["one", "two", "three"]
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);// => [1, 3]console.log(evens);// => [2, 4]
js remove several elements from array
var ar = [1, 2, 3, 4, 5, 6];ar.pop(); // returns 6console.log( ar ); // [1, 2, 3, 4, 5]
js remove several elements from array
var ar = [1, 2, 3, 4, 5, 6];ar.length = 4; // set length to remove elementsconsole.log( ar ); // [1, 2, 3, 4]
js remove several elements from array
var arr1 = [1, 2, 3, 4, 5, 6];var arr2 = arr1; // Reference arr1 by another variable arr1 = [];console.log(arr2); // Output [1, 2, 3, 4, 5, 6]