SpinTheMic
Pro

Interview practice question

Unexpected behaviour from sparse arrays

Frontend Engineering · JavaScript Core · Experienced

A function behaves strangely because an array has "holes," like [1, , 3]. What's happening, and how do you handle it?

What a strong answer covers

Your AI report card counts how many of these ideas you cover.

  • Holes are missing indexes, not undefined.
  • forEach/map skip holes; for...of yields undefined.
  • Created by new Array(n), delete, length changes.
  • Avoid creating holes (Array.from, fill).
  • Normalise inputs.
Practise this topic

Start without signing up. Sign in free to get an AI report card on your answer.

See all topics