existing ["562fae5a626ca2e032947baa"] new array [ { _id: '562fae5a626ca2e032947baa' }, { _id: '562fae57626ca2e032947ba9' } ] modified [ { _id: '562fae5a626ca2e032947baa' }, { _id: '562fae57626ca2e032947ba9' } ] I have an existing array and a new array, i want to compare the existing and the new array and remove the duplicates.
var existing = ["562fae5a626ca2e032947baa"]; var newArr = [ { _id: '562fae5a626ca2e032947baa' }, { _id: '562fae57626ca2e032947ba9' } ]; newArr = newArr.filter(function(val){ return existing.indexOf(val) == -1; }); console.log(newArr); When i try to print newArr, i still get the two objects?
modified [ { _id: '562fae5a626ca2e032947baa' }, { _id: '562fae57626ca2e032947ba9' } ] I want the modified array to have only.
modified [{ _id: '562fae57626ca2e032947ba9' } ] Below is the fiddle. http://jsfiddle.net/ema6upg1/2/
existingto the objects that are innewArr.