Skip to content

Instantly share code, notes, and snippets.

@AidarGatin
Last active May 2, 2019 13:55
Show Gist options
  • Save AidarGatin/b83f7984f151ea02e44aeb7a6c4fe364 to your computer and use it in GitHub Desktop.
Save AidarGatin/b83f7984f151ea02e44aeb7a6c4fe364 to your computer and use it in GitHub Desktop.
JS JavaScript ES6 Filter Unique Values in Array
//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
@AidarGatin
Copy link
Author

If you have objects array , you need a different approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment