Home > front end >  find and create a new array just with one sort of value and eliminate duplicates (if many) [duplicat
find and create a new array just with one sort of value and eliminate duplicates (if many) [duplicat

Time:09-21

I'm trying to find a method for sorting an array by uuid and eliminate the duplicate.

For exemple i have a array like this :

const x = [
{id: 1, uuid: xxxx-xxxx-xxxx-xxxx, content: 'string'},
{id: 2, uuid: xxxx-xxxx-xxxx-xxxx, content: 'string'},
{id: 3, uuid: xxxx-xxxx-xxxx-xxxx, content: 'string'},
{id: 4, uuid: xxxx-xxxx-xxxx-xxxx, content: 'string'},
{id: 5, uuid: xxxx-xxxx-xxxx-xxxx, content: 'string'},
{id: 6, uuid: xxxx-xxxx-xxxx-xxxx, content: 'string'},
{id: 7, uuid: yyyy-yyyy-yyyy-yyyy, content: 'string'},
{id: 8, uuid: zzzz-zzzz-zzzz-zzzz, content: 'string'}
]

And i'm trying to find a simple way for making this in result :

const x = [xxxx-xxxx-xxxx-xxxx, yyyy-yyyy-yyyy-yyyy, zzzz-zzzz-zzzz-zzzz]

I know it's maybe basic but my brain is off i guest ...

Thanks !

CodePudding user response:

Try this, but i used a string type for uuid:

[...new Set(x.map(e => e.uuid))].sort()
  • Related