Skip to content

Instantly share code, notes, and snippets.

@darbicus
Created April 11, 2014 15:09
Show Gist options
  • Save darbicus/10476513 to your computer and use it in GitHub Desktop.
Save darbicus/10476513 to your computer and use it in GitHub Desktop.
filter out objects that have the same id
var array = [{
'id': 1
}, {
'id': 2
}, {
'id': 2
}, {
'id': 2
}];
var a = array.filter(function (e) {
return !array.some(function (g) {
return g.id === e.id && array.indexOf(e) > array.indexOf(g);
});
});
/// a = [{ 'id': 1}, { 'id': 2}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment