95
rated 0 times
[
98]
[
3]
/ answers: 1 / hits: 8181
/ 10 Years ago, fri, july 25, 2014, 12:00:00
I am trying to find the difference betweeen two arrays of objects using underscore js library.
More From » coffeescript
I am trying to find the difference betweeen two arrays of objects using underscore js library.
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})