I ran into a scenario, I'll simplify the data to user/project, where I needed to take values like:
users: [
{name: 'bob', project: 1},
{name: 'sam', project: 2},
{name: 'ted', project: 3},
];
and given an array of project ids I wish to exclude such as
excludeProjects: [1,3];
I want to return [{name: 'sam', project: 2}];
I was able to do this with a custom filter function:
let usersNotInProject = _.filter(users, function(o) {
for (var i=0; i<excludeProjects.length; i++){
if (excludeProjects[i]===o.project){
return false;
}
}
return true;
});
However, I believe I am missing some more elegant way to do this with lodash. Is a custom function really needed for this scenario?
users.filter(user => !excludeProjects.includes(user.project))
\$\endgroup\$