Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save msaxena25/a8b34d644167b7e40f57474c25f9483b to your computer and use it in GitHub Desktop.
Save msaxena25/a8b34d644167b7e40f57474c25f9483b to your computer and use it in GitHub Desktop.
Array (contains Object type element) get Unique objects items only
1. Compare two arrays contains Object type element
2. Below we are checking based on one property "id"
3. remove duplicate items
(<any>Array.prototype).unique = function () {
var a = this.concat();
for (var i = 0; i < a.length; ++i) {
for (var j = i + 1; j < a.length; ++j) {
if (a[i].id === a[j].id) // checking based on id property
a.splice(j--, 1);
}
}
return a;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment