javascript - Removing duplicate values from two arrays -
existing ["562fae5a626ca2e032947baa"] new array [ { _id: '562fae5a626ca2e032947baa' }, { _id: '562fae57626ca2e032947ba9' } ] modified [ { _id: '562fae5a626ca2e032947baa' }, { _id: '562fae57626ca2e032947ba9' } ]
i have existing
array , new
array, want compare
existing
, new array
, remove duplicates
.
var existing = ["562fae5a626ca2e032947baa"]; var newarr = [ { _id: '562fae5a626ca2e032947baa' }, { _id: '562fae57626ca2e032947ba9' } ]; newarr = newarr.filter(function(val){ return existing.indexof(val) == -1; }); console.log(newarr);
when try print newarr, still 2 objects?
modified [ { _id: '562fae5a626ca2e032947baa' }, { _id: '562fae57626ca2e032947ba9' } ]
i want modified array have only.
modified [{ _id: '562fae57626ca2e032947ba9' } ]
below fiddle. http://jsfiddle.net/ema6upg1/2/
newarr.filter(function(val){ return existing.indexof(val._id) == -1; })
is need, val object, need compare _id
Comments
Post a Comment