Home > Software engineering >  Why can't I add string to a Set properly?
Why can't I add string to a Set properly?

Time:04-23

First example. I can't add string just writing it in ().

let set = new Set('Emily', 'Mag');

enter image description here

Where's 'Mag'? String is iterable, why doesn't it add to Set collection?

CodePudding user response:

I think the syntax is slightly off. What you might be looking for is the following:

let set = new Set(['Emily', 'Mag']);

Hope it helps!

  • Related