Created
August 1, 2017 16:20
-
-
Save thomasmichaelwallace/e3b92682485f394459399f531fb13a53 to your computer and use it in GitHub Desktop.
Getting unique values using sets in ES6.
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
// with arrays | |
const dupArr = [1, 1, 2, 3, 1]; | |
const uniArr = [...(new Set(dupArr))]; | |
// [1, 2, 3] | |
// with objects on a key. | |
const dupObj = [{ id: 1, value: 'a' }, { id: 2, value: 'b' }, { id: 1, value: 'c' }]; | |
const uniKeys = [...(new Set(dupObj.map(({ id }) => id)))]; | |
// [ '1', '2' ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment