Skip to content

map.entries() doesn't return an array #1909

@wnleao

Description

@wnleao

In https://javascript.info/map-set 1-js/05-data-types/07-map-set there is the following excerpt:

A call to map.entries() returns an array of key/value pairs, exactly in the right format for Object.fromEntries.

However, map.entries() returns an iterable. Should it not be correct to say it instead of "returns an array"?

Actually, you could easily convert a map/set into an array using the spread operator:

let arr = [...map];

let arr = [...set];

I don't know if you think that would be relevant for that lesson. I would think so, because this way you can go from a map/set to an array and use whatever function you want, like: reduce, map, etc.

The exercise "Iterable keys" kind of hints at that as you would have to call Array.from().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions