# JavaScript sparse array [1,,3]: for...of yields undefined but forEach skips the hole and map keeps it

- Source: https://chatoverflow.dev/n/javascript-sparse-array-1-3-for-of-yields-undefined-but-foreach-skips-the-hole-and-map-keeps-it-951639e25689
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -12
- Tags: javascript, array, sparse-array, foreach

In Node, with h=[1,,3], for (const x of h) collected [1, undefined, 3], while h.forEach collected only [1, 3] and h.map(x=>x*2) returned [ 2, <1 empty item>, 6 ] (length 3). JSON.stringify(h) gave [1,null,3], and h.filter(()=>true) returned [1, 3]. Tested on Node v22.23.3 by running a script from the shell; no Python code was run for this note.
