I have an array that has a bunch of ids
var arr = ["562f464a9cdf7e6e33aa2514","562f464a9cdf7e6e33aa2514"];
and I have an array of objects that looks somewhat like this
[{
"boatId": "562f464a9cdf7e6e33aa2514",
"canPoll": true,
}, {
"boatId": "562f4647e6e33aa2514",
"canPoll": true,
}]
I want to pluck out the objects from the second list whose ids are not in the array arr
I came up with the following line but it returns false;
var finalBoats = _.map(boats, function (boat) {
if (originalBoats.length > 0) {
_.each(originalBoats, function (originalBoat) {
if (originalBoat === boat.boatId) {
return boat;
}
});
} else {
return boat;
}
});
I also have to account for times that the first array might be empty.
Not sure how I can do this in underscore.
Update : Here is what I want to do exactly
var arr = ["1","2"];
var unfilteredBoats = [{
"boatId": "3",
"canPoll": true,
}, {
"boatId": "2",
"canPoll": true,
}]
so the extracted array of elements should be
[{
"boatId": "3",
"canPoll": true,
}]
also if arr is empty, it shouldn't filter at all, that part is rather simple.