compsci45000
compsci45000

Reputation: 379

Difference between two arrays of objects coffeescript using underscore js

I am trying to find the difference betweeen two arrays of objects using underscore js library.

Upvotes: 6

Views: 8180

Answers (1)

Gabriel
Gabriel

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

Related Questions