The blog post describes how various functions and methods that deal with arrays are affected by holes [1].
var arr = [ 'a',, 'b' ];Above, we have created an array that has the element 'a' at index 0, a hole (no element at all) at index 1 and the element 'b' at index 2.
> [ 'a', 'b', ] [ 'a', 'b' ] > [ 'a', 'b',, ] [ 'a', 'b', , ]
var arr2 = arr.slice();The right-hand side of the above assignment is equivalent to:
arr.slice(0, arr.length)
> arr.forEach(function (x,i) { console.log(i+'.'+x) }) 0.a 2.bevery() also skips holes (similarly: some()):
> arr.every(function (x) { return x.length === 1 }) truemap() skips, but preserves holes:
> arr.map(function (x,i) { return i+'.'+x }) [ '0.a', , '2.b' ]filter() eliminates holes:
> arr.filter(function (x) { return true }) [ 'a', 'b' ]join() converts holes and undefineds to empty strings.
> arr.join('-') 'a--b' > [ 'a', undefined, 'b' ].join('-') 'a--b'
> var arr2 = arr.slice() > arr2.sort() [ 'a', 'b', , ]
> var arr2 = arr.slice() > arr2.foo = 123; > for(var key in arr2) { console.log(key) } 0 2 foo
> Array.apply(null, Array(3)) [ undefined, undefined, undefined ]apply() nicely plugs holes of empty arrays. You cannot, however use it to do so for arbitrary arrays, which may or may not contain holes. For example, the arbitrary array [2] does not contain holes, so apply() should return it “unchanged”. But it doesn’t, it creates an empty array whose length is 2 (because the function Array() interprets single numbers as array lengths, not as array elements).
> Array.apply(null, [2]) [ , ,]