Repository navigation
Confusing inspection for sparse arrays #11570
Description
Activity
- addedutilIssues and PRs related to the built-in util module.Issues and PRs related to the built-in util module.
on Feb 26, 2017 I agree it's confusing but I think it's correct. Due to the trailing comma,
[ , , ]is actually a two-element array, not three:> new Array(3).length 3 > [ , , ].length 2Reacted by Jeremiah SenkpielYeah, the REPL is doing its job alright. It's just the inspection is a bit counter-intuitive.
Personally I'm leaning more towards Firefox's approach. It's clear and unambiguous, and I'm worried the Unicode
×character used in Chrome's version might not be friendly towards Windows terminals. Substitutes like the letter X might be confusing in themselves.@TimothyGu @bnoordhuis what about something like this?
> new Array(3) [ [3 empty] ] > [1, 2, , , , 3, 4, 5] [ 1, 2, [3 empty], 3, 4, 5 ] > [1, 2, , , , 3, 4, 5, , 2] [ 1, 2, [3 empty], 3, 4, 5, [1 empty], 2 ]I'd be okay with that. Personally I'd prefer the
[3 empty]to have the same color asundefinedjust to be consistent, though that's bikeshedding.@TimothyGu IMO it's more appropriate to mark it with
specialstyle, but ¯\_(ツ)_/¯- added a commit that references this issue
on Mar 7, 2017 - added a commit that references this issue
on Mar 21, 2017 36 remaining items
- added a commit that references this issue
on Jun 3, 2024 - added a commit that references this issue
on Jul 15, 2024 - added a commit that references this issue
on Aug 22, 2024 - added a commit that references this issue
on Oct 2, 2024 - added a commit that references this issue
on Nov 18, 2024 - added a commit that references this issue
on Dec 18, 2024 - added a commit that references this issue
on Jan 20, 2025 - added a commit that references this issue
on Mar 17, 2025 - added a commit that references this issue
on Jun 27, 2025 - added a commit that references this issue
on Aug 21, 2025 - added a commit that references this issue
on Sep 26, 2025 - added a commit that references this issue
on Nov 21, 2025 - added a commit that references this issue
on Feb 24, 2026 - added a commit that references this issue
on Apr 16, 2026 - added a commit that references this issue
on Jul 27, 2026

In the
nodeREPL, sparse elements of an array are shown as "empty":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:
Firefox is more upfront: