Last active
January 6, 2022 13:48
-
-
Save mecmartini/bf29a6b959b88e0d1a9849edac84a249 to your computer and use it in GitHub Desktop.
Javascript Set with objects
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
const data = [ | |
{a: 1, b: 2, c: 3}, | |
{a: 4, b: 5, c: 6}, | |
{a: 1, b: 2, c: 3}, | |
{a: 4, b: 5, c: 6}, | |
]; | |
const dataSetRaw = new Set(); | |
data.map( (item) => ( | |
dataSetRaw.add( | |
JSON.stringify(item) | |
) | |
)); | |
const dataSet = Array.from(dataSetRaw).map( (item) => JSON.parse(item) ); | |
console.log('dataSet', dataSet); | |
/*output | |
[ | |
{"a":1,"b":2,"c":3}, | |
{"a":4,"b":5,"c":6} | |
] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment