Skip to content

Instantly share code, notes, and snippets.

@johnpili
Last active September 10, 2017 12:09
Show Gist options
  • Save johnpili/1c8cf5471391d9a0b16f8aabe9c47447 to your computer and use it in GitHub Desktop.
Save johnpili/1c8cf5471391d9a0b16f8aabe9c47447 to your computer and use it in GitHub Desktop.
Javascript extract distinct list of objects based on key
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