-2

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 !

1 Answers1

2

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

[...new Set(x.map(e => e.uuid))].sort()
DecPK
  • 24,537
  • 6
  • 26
  • 42
D4NT3
  • 141
  • 7