Last active
September 10, 2017 12:09
-
-
Save johnpili/1c8cf5471391d9a0b16f8aabe9c47447 to your computer and use it in GitHub Desktop.
Javascript extract distinct list of objects based on key
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
function extractDistinctObjects(key, items) { | |
var tmp = []; | |
items.filter(function(item){ | |
if(tmp.findIndex(x => x[key] == item[key]) <= -1) { | |
tmp.push(item); | |
} | |
}); | |
return tmp; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment