-1

I have this object, and I want Remove duplicates and make it into one array

var sports = [
  ['basketball','fotball','racing'],
  ['fotball','basketball','swimming'],
];

What is the best way to get it like this:

['basketball','fotball','racing','swimming'],

The flat() will make the sports into one array, and is probably the best option here? Just have to remove the duplicates any tips?

bacco2
  • 300
  • 2
  • 9

1 Answers1

0

use below:

[...new Set(sports.flat())]

Here sports.flat() flatten out the array. See the doc here

and new Set() will make them unique. See the doc here

sky blue
  • 35
  • 6
  • 1
    While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. You can find more information on how to write good answers in the help center: https://stackoverflow.com/help/how-to-answer . Good luck – nima Oct 07 '21 at 09:30