Array `forEach` not iterating all elements
· ☕ 2 min read
I like Array.forEach() and use it whenever I need to iterate through elements. However one needs to be aware of its quirk.
1 2 3 const arr = new Array(5); arr[0] = 0; arr[4] = 4; A typical for outputs all elements including those not initialized yet (hold your breath for a moment on the initialized thing).