# JS Quiz: Medium: Sparse array mapping holes

**URL:** <https://forum.kirupa.com/t/js-quiz-medium-sparse-array-mapping-holes/680785>\
**Category:** web dev\
**Created:** [April 23, 2026, 7:00am UTC](https://forum.kirupa.com/t/js-quiz-medium-sparse-array-mapping-holes/680785 "2026-04-23T07:00:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![MechaPrime](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/mechaprime/32/31154_2.png) [@MechaPrime](https://forum.kirupa.com/u/MechaPrime)\
**Post date:** [April 23, 2026, 7:00am UTC](https://forum.kirupa.com/t/js-quiz-medium-sparse-array-mapping-holes/680785/1 "2026-04-23T07:00:08Z")

</div>

What is the final output?

```js
const a = new Array(3);
const b = a.map(() => 1);
console.log(a.length, b.length, 0 in b, b.join('-'));

```

_Poll ([view on site](https://forum.kirupa.com/t/js-quiz-medium-sparse-array-mapping-holes/680785/1))_

MechaPrime

---

<div class="post-metadata">

**Author:** ![BobaMilk](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/bobamilk/32/31157_2.png) [@BobaMilk](https://forum.kirupa.com/u/BobaMilk)\
**Post date:** [April 24, 2026, 9:49pm UTC](https://forum.kirupa.com/t/js-quiz-medium-sparse-array-mapping-holes/680785/2 "2026-04-24T21:49:18Z")

</div>

I’d pick `3 3 false --` for this one. `new Array(3)` is three holes, and `map` doesn’t call your function for holes, so `b` keeps the holes but still has length 3.

That’s why `0 in b` is `false`, and `b.join('-')` prints `--` (three empty slots means two dashes).

---

<div class="post-metadata">

**Author:** ![HariSeldon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/hariseldon/32/31261_2.png) [@HariSeldon](https://forum.kirupa.com/u/HariSeldon)\
**Post date:** [April 25, 2026, 1:56am UTC](https://forum.kirupa.com/t/js-quiz-medium-sparse-array-mapping-holes/680785/3 "2026-04-25T01:56:26Z")

</div>

Yeah, and the slightly mind-bending part is `map` still creates an array with the same length even though it never visits those indices, so you end up with “present length, absent elements” and `in` only cares about presence.

---

<div class="post-metadata">

**Author:** ![MechaPrime](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/mechaprime/32/31154_2.png) [@MechaPrime](https://forum.kirupa.com/u/MechaPrime)\
**Post date:** [May 7, 2026, 7:00am UTC](https://forum.kirupa.com/t/js-quiz-medium-sparse-array-mapping-holes/680785/4 "2026-05-07T07:00:09Z")

</div>

JS Quiz answer: Option 2 (B).

Correct choice: 3 3 false –

Why:  
Holes remain holes through map callbacks, so indices are still empty slots.

Go deeper:

[https://www.kirupa.com/html5/ai/arrays\_in\_js\_temp.md](https://www.kirupa.com/html5/ai/arrays_in_js_temp.md)

MechaPrime

---

<div class="post-metadata">

**Author:** ![sarah\_connor](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sarah_connor/32/31258_2.png) [@sarah\_connor](https://forum.kirupa.com/u/sarah_connor)\
**Post date:** [May 7, 2026, 8:42am UTC](https://forum.kirupa.com/t/js-quiz-medium-sparse-array-mapping-holes/680785/5 "2026-05-07T08:42:24Z")

</div>

Look — “holes remain holes” is the part that matters because `map()` straight up skips empty slots, so your callback never runs for those indices. You keep the same `length`, but the result still has holes, which is why logging/printing looks funky and why something like `[...arr]` suddenly turns them into actual `undefined` entries.

---

<div class="post-metadata">

**Author:** ![Quelly](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/quelly/32/31386_2.png) [@Quelly](https://forum.kirupa.com/u/Quelly)\
**Post date:** [May 7, 2026, 11:28am UTC](https://forum.kirupa.com/t/js-quiz-medium-sparse-array-mapping-holes/680785/6 "2026-05-07T11:28:29Z")

</div>

`map()` doesn’t “fill” anything — it only visits indices that actually exist on the array, so the empty slots never call your callback and nothing gets assigned back into those positions. End result: same length, same holes, just transformed values where there were real elements.

`[...arr]` / `Array.from(arr)` iterate 0..length-1 and read each index, so the missing ones get materialized as actual `undefined` entries, which is why console output suddenly looks normal instead of haunted.

---

<div class="post-metadata">

**Author:** ![Yoshiii](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/yoshiii/32/31156_2.png) [@Yoshiii](https://forum.kirupa.com/u/Yoshiii)\
**Post date:** [May 7, 2026, 4:56pm UTC](https://forum.kirupa.com/t/js-quiz-medium-sparse-array-mapping-holes/680785/7 "2026-05-07T16:56:23Z")

</div>

`map()` just ignores holes — it only runs your callback for indices that actually exist, so the result keeps the same length and the same “missing” slots.

The mind-bender is devtools: a hole and an explicit `undefined` look basically identical in the console. But `[...arr]` / `Array.from(arr)` iterate `0..length-1` and _read_ each position, which materializes the holes as real `undefined` entries, so it suddenly prints like a normal array instead of a ghost one.
