Skip to content

Confusing inspection for sparse arrays #11570

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":

>newArray(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:

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

Firefox is more upfront:

>newArray(3)Array[<3emptyslots> ]
>[undefined,,undefined]// to differentiate between a hole and `undefined`Array[undefined,<1emptyslot>, 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