jquery - Remove duplicate objects in an array of object in JavaScript -
object1 = {connectorindex: 1, nodeid: 6, connectors: object} object2 = {connectorindex: 1, nodeid: 6, connectors: object} connector: {name: "aland", key: "", description: "departure country (country goods sent)"}
there 2 objects in same array. connector objects identical. how remove duplicate elements , final array 1 object?
var array = [object 1, object 2];
object 2
duplicate remove array.
this if looking exact matches:
function remove_duplicates(objectsarray) { var usedobjects = {}; (var i=objectsarray.length - 1;i>=0;i--) { var = json.stringify(objectsarray[i]); if (usedobjects[so]) { objectsarray.splice(i, 1); } else { usedobjects[so] = true; } } return objectsarray; } var objectsarray = [{a:'foo',b:'bar'}, {a:'foo',b:'bar'}]; var clean = remove_duplicates(objectsarray);
Comments
Post a Comment