Skip to content

Instantly share code, notes, and snippets.

@AlonsoK28
Last active December 7, 2021 03:54
Show Gist options
  • Save AlonsoK28/4d565d328b7cbd944824dea9e749b85e to your computer and use it in GitHub Desktop.
Save AlonsoK28/4d565d328b7cbd944824dea9e749b85e to your computer and use it in GitHub Desktop.
remove first-class object array items from another array
// just copy and paste into your console and go on
const example = [
{
name: 'Miles Toms',
age: 33,
city: 'Brazil'
},
{
name: 'Jhones Miller',
age: 20,
city: 'Mexico'
},
{
name: 'Miller Mark',
age: 11,
city: 'USA'
},
{
name: 'Moe Jhonson',
age: 30,
city: 'Argelia'
},
{
name: 'Miller Thomas',
age: 21,
city: 'Tokyo'
},
{
name: 'Anna Jhones',
age: 11,
city: 'Italy'
},
{
name: 'Rin Miller',
age: 45,
city: 'China'
},
{
name: 'Drake Miles',
age: 40,
city: 'Russia'
},
{
name: 'Tim Miller',
age: 31,
city: 'Argentina'
}
];
const myRes = example.filter((item) => {
const toRemove = ['Anna', 'Drake', 'Moe', 'Ho'];
const match = toRemove.some(matchName)
if(!match) return item;
function matchName(el){
const currentName = item.name.toLowerCase();
const currentMatch = el.toLowerCase();
return currentName.includes(currentMatch);
}
});
console.log('myRes: ', myRes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment