I
I
Ivanushka2552022-04-21 23:02:02
JavaScript
Ivanushka255, 2022-04-21 23:02:02

Is it correct to use non-iterable elements inside a Set?

MDN says that ([])only iterable elements can be used internally .

new Set([iterable]);

However, it's not entirely clear to me. Using this construction, I can put a non-iterable object there, and everything will work. For example: What does MDN mean here?
let set = new Set([{key: 'value'}, 23]);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Inviz Custos, 2022-04-21
@Ivanushka255

You need to practice reading the documentation a little.
[] means an optional argument, not an array as you might think.
In your example, you are passing an array, which is an iterable object.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question