Skip to content

Instantly share code, notes, and snippets.

@web2ls
Created August 13, 2021 09:53
Show Gist options
  • Select an option

  • Save web2ls/b92b34037e5f81abbfc75eb7f8736b8b to your computer and use it in GitHub Desktop.

Select an option

Save web2ls/b92b34037e5f81abbfc75eb7f8736b8b to your computer and use it in GitHub Desktop.
Function to get array with only unique elements
function getUnique(array) {
const u = {};
const a = [];
for (let i = 0, l = array.length; i < l; ++i) {
if (u.hasOwnProperty(array[i])) {
continue;
}
a.push(array[i]);
u[array[i]] = 1;
}
return a;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment