Skip to content

Confusing inspection for sparse arrays #11570

Closed
@TimothyGu

Description

@TimothyGu
  • Version: all supported versions (oldest tested branch is v4.x (4.8.0))
  • Platform: all
  • Subsystem: util

In the node REPL, sparse elements of an array are shown as "empty":

> new Array(3)
[ , ,  ]

However, when one copy the resulting [ , , ] and reenter it into the prompt, a different array is shown, thus confusing the developer:

> [ , ,  ]
[ ,  ]

How the Chrome inspector deals with this situation is explicitly make the inspected result not compliant JS:

> new Array(3)
[undefined × 3]
> [undefined, , undefined] // to differentiate between a hole and `undefined`
[undefined, undefined × 1, undefined]

Firefox is more upfront:

> new Array(3)
Array [ <3 empty slots> ]
> [undefined, , undefined] // to differentiate between a hole and `undefined`
Array [ undefined, <1 empty slot>, undefined ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    utilIssues and PRs related to the built-in util module.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions