Last active
May 2, 2019 13:55
-
-
Save AidarGatin/b83f7984f151ea02e44aeb7a6c4fe364 to your computer and use it in GitHub Desktop.
JS JavaScript ES6 Filter Unique Values in Array
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
//Filter Array for Unique Values JavaScript Snippet | |
const array = [1, 1, 2, 2, 3, 3, 5, 5, 1, 4] | |
const uniqueArray = [...new Set(array)]; | |
console.log(uniqueArray); | |
// Result: [1, 2, 3, 5, 4] | |
// works for arrays containing primitive types: undefined, null, boolean, string and number |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you have objects array , you need a different approach.