DEV Community

Discussion on: Introduction to Sets in JavaScript – All You Need to Know

Collapse
 
jankowskij profile image
JJankowski

I'm puzzled why entries() return an array for each element, containing the same thing twice. What's the use of that?

Collapse
 
alexdevero profile image
Alex Devero

This is just a guess. It could be for compatibility reasons. Objects (literals) contain data in the form of key-value pairs. The entries() should return both, key and value. Sets contain only values. Adding duplicates can be a way to make the result of entries() and its format consistent.