Skip to content
Advertisement

How to get new Set from array of arrays by using Array.map function?

Exploring Sets now and could not get a new Set from an array of x arrays in it. I what to use Array.map method inside new Set().

Here is what I’m trying to do, and it seems logical, but in the end having values only from the 1st array:

JavaScript

Will be awesome to understand what I am doing wrong and how it should look like

Update: To be more clear in my need:

JavaScript

My goal to have [1,2,3,4,5] but getting [1,3,4]

Solution:

JavaScript

Advertisement

Answer

You need only the array, not spreaded parameters:

JavaScript

From Set:

Syntax

JavaScript

With a nested array, you need a flat it first:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement