Skip to content

Instantly share code, notes, and snippets.

@mecmartini
Last active January 6, 2022 13:48
Show Gist options
  • Save mecmartini/bf29a6b959b88e0d1a9849edac84a249 to your computer and use it in GitHub Desktop.
Save mecmartini/bf29a6b959b88e0d1a9849edac84a249 to your computer and use it in GitHub Desktop.
Javascript Set with objects
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