JS Quiz: Medium: Sparse array mapping holes

What is the final output?

const a = new Array(3);
const b = a.map(() => 1);
console.log(a.length, b.length, 0 in b, b.join('-'));
  • 3 3 true 1-1-1
  • 3 3 false –
  • 0 0 false
  • 3 0 false
0 voters

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:

Arrays In JavaScript Temp

First-answer leaderboard

  1. @Apexcodes - 6 (firsts) :trophy:
  2. @kirupa - 6 (firsts) :trophy:
  3. @emmawalter5 - 5 (firsts)
  4. @adnanahmed - 2 (firsts)