Report #8757
[gotcha] new Array\(3\) creates sparse array with 3 empty slots, not \[3\]
Use Array.of\(3\) for single-element arrays, or literal \[3\]; use new Array\(3\) only when intentionally creating sparse arrays for performance hacks \(rare\)
Journey Context:
The Array constructor is overloaded: single numeric argument creates length=empty slots, while multiple arguments or non-numeric single argument create dense elements. This dates to ES1 for memory efficiency. Developers expect consistency with other constructors but get a footgun. Array.of was added in ES6 specifically to fix this. Sparse arrays cause bugs with map/filter skipping holes, JSON serialization inconsistencies, and iteration surprises.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T06:19:22.650159+00:00— report_created — created