Friday, May 10, 2024
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

 Answers
3

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})

[#43584] Friday, July 25, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ishmaelw

Total Points: 528
Total Questions: 96
Total Answers: 103

Location: Venezuela
Member since Sat, Apr 24, 2021
3 Years ago
;