Skip to content

Instantly share code, notes, and snippets.

@luislobo14rap
Created January 29, 2020 18:57
Show Gist options
  • Save luislobo14rap/b4d81233849f4443afccb368bea79a3f to your computer and use it in GitHub Desktop.
Save luislobo14rap/b4d81233849f4443afccb368bea79a3f to your computer and use it in GitHub Desktop.
uniqueObjs.js
// uniqueObjs.js v1
function uniqueObjs(array_) {
let compare = [];
let unique = [];
for (let i = 0; i < array_.length; i++) {
let thisObj = array_[i];
let objAsString = JSON.stringify(thisObj).toLowerCase();
if (compare.indexOf(objAsString) == -1) {
compare.push(objAsString);
unique.push(thisObj);
};
};
return unique;
};
@luislobo14rap
Copy link
Author

Example: uniqueObjs([{a:1,b:2,c:3}, {a:2,b:2,c:3}, {a:1,b:2,c:3}, {a:1,b:2,c:3}, {a:2,b:2,c:3}, {a:1,b:2,c:3}]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment