Reputation: 379
I am trying to find the difference betweeen two arrays of objects using underscore js library.
Upvotes: 6
Views: 8180
Reputation: 473
Do you want to use the difference function of underscore? You can do this:
_.difference([1, 2, 3, 4, 5], [5, 2, 10])
this works in coffeescript.
EDIT
Using an array of objects and comparing the id property
arrayOne = [{id: 1}, {id: 2}]
arrayTwo =[{id: 2}, {id: 3}]
_.select arrayOne, (item) ->
!_.findWhere(arrayTwo, {id: item.id})
Upvotes: 13