Why does [].push([]) return 1? [duplicate]

.push() returns the new length of the array.

['one'].push('two'); // returns 2 (array length is 2)
['one', 'two'].push('something'); // returns 3 (array length is 3)

In your case:

[].push([]); // array length is 1 where you get array within array. [[]]

Leave a Comment