Created
August 13, 2021 09:53
-
-
Save web2ls/b92b34037e5f81abbfc75eb7f8736b8b to your computer and use it in GitHub Desktop.
Function to get array with only unique elements
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 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