Skip to content

Instantly share code, notes, and snippets.

@xdesro
Created June 15, 2021 19:54
Show Gist options
  • Save xdesro/ab4d8de1833e4e68a303fc6fc3f172d7 to your computer and use it in GitHub Desktop.
Save xdesro/ab4d8de1833e4e68a303fc6fc3f172d7 to your computer and use it in GitHub Desktop.
Using a JS Set and Array.flat() to get only the unique values from many arrays.
const clients = [
{
name: 'Client A',
services: ['Web development', 'SEO', 'Web design', 'Full service agency'],
},
{
name: 'Client B',
services: [
'Analytics', 'Email marketing', 'Marketing', 'SEO', 'Web design', 'Web development', 'Integration solutions', 'Full service agency','Advertising',
],
},
];
const uniqueServices = [
...new Set(clients.map(({services}) => services).flat()),
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment