javascript - Lodash/Underscore : Check for a value within an array, in an array of objects -
confusing title, simple way explain show i'm after :
var user = [ {foo:"test",bar:1}, {foo:"test2",bar:2} ]; var items = [{foo:"test",bar:1},{foo:"test4",bar:4},{foo:"test5",bar:5}]
what want, pick one item items
not in user
, , add user
. in case user
object end looking :
user = [ {foo:"test",bar:1}, {foo:"test2",bar:2}, {foo:"test4",bar:4} ];
i've tried sorts of _.filter, _.contains, etc... combinations, can't quite figure out. appreciated!
the logic follows: want find first item not contained within user
array.
so can following:
var item = _.find(items, function (item) { return !_.findwhere(user, item); });
Comments
Post a Comment