Many built-in data structures (ex. Map
) expose an iterator with the well known @@iterator
(Symbol.iterator
) key and the #entries()
instance method.
Some built-in data structures (ex. Array
) are the same but with @@iterator
and #values()
.
Some built-in data structures (ex. Set
) are the same but with @@iterator
and #keys()
.
Some built-in data structures support all 3 methods for the same iterator. I think Set
is the only one that does this.
Having a rule to ensure consistent usage of these iterators can be helpful for maintaining convention in a codebase.
When preferring @@iterator
:
for (const x of map.entries()) {}
[...map.entries()];
new Map(map.entries());
[...array.values()];
When preferring #entries()
, #values()
, or #keys()
:
for (const x of map) {}
[...map];
new Map(map);
[...array];
When preferring #entries()
, #values()
, or #keys()
:
for (const x of map.entries()) {}
[...map.entries()];
new Map(map.entries());
When preferring @@iterator
:
for (const x of map) {}
[...map];
new Map(map);
Built-in data structures that should support @@iterator
and #entries()
:
Map
Set
FormData
(the global, not the one from form-data
)URLSearchParams
Built-in data structures that should support @@iterator
and #values()
:
Array
Set
TypedArray
Built-in data structures that should support @@iterator
and #keys()
:
Set
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too