Unable to Create New Set From Array

Advertisements

I am trying to create new Sets from an array but it is returning an empty object. What am I doing wrong?

const myArray = ["value1", "value2", "value3", "value1", "value2"];
const mySet = new Set(myArray);
Logger.log(mySet);

>Solution :

new Set() returns the Set object. When you want to see the value, how about the following modification?

From:

Logger.log(mySet);

To:

Logger.log([...mySet]);

or

Logger.log(Array.from(mySet));

References:

Leave a Reply Cancel reply