javascript - How to get the difference of arrays in UnderscoreJS or angularJS -


i have 2 array of objects:

1) [{id:1}{id:2}{id:3}{id:4}{id:5}]  2) [{id:1}{id:2}{id:3}] 

is there in build function in underscorejs or angularjs give me output :

[{id:4}{id:5}] 

i tried using _.difference , _.without not working work on simple arrays not on array of objects

thanks in advance.

function diff(a, b) {   return _.filter(a, function(val) {     return !_.findwhere(b, val);   }); }  diff[{id:1}, {id:2}, {id:3}, {id:4}, {id:5}], [{id:1}, {id:2}, {id:3}]); // [{id:4}, {id:5}] 

this solution specific data structure , not work any array of objects.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -