Created
January 29, 2020 18:57
-
-
Save luislobo14rap/b4d81233849f4443afccb368bea79a3f to your computer and use it in GitHub Desktop.
uniqueObjs.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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}]);