remove item from array if exists in another array
myArray = myArray.filter( ( el ) => !toRemove.includes( el ) );
remove item from array if exists in another array
myArray = myArray.filter( ( el ) => !toRemove.includes( el ) );
remove item from array if exists in another array
myArray = myArray.filter( function( el ) {
return !toRemove.includes( el );
} );
remove item from array if exists in another array
$filteredFoo = array_diff($foo, $bar);
remove item from array if exists in another array
myArray = myArray.filter( function( el ) {
return toRemove.indexOf( el ) < 0;
} );
remove an element in array useing another array
Remove an item comparing from other array
const toRemoveMap = toRemove.reduce(
function(memo, item) {
memo[item] = memo[item] || true;
return memo;
},
{} // initialize an empty object
);
const filteredArray = myArray.filter(function (x) {
return toRemoveMap[x];
});
// or, if you want to use ES6-style arrow syntax:
const toRemoveMap = toRemove.reduce((memo, item) => ({
...memo,
[item]: true
}), {});
const filteredArray = myArray.filter(x => toRemoveMap[x.id]);
From <https://stackoverflow.com/questions/19957348/remove-all-elements-contained-in-another-array>
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us