2

Why does this code produce an array of 20 elements which are all undefined:

> Array(20).map(function() { return 3; })
[ , , , , , , , , , , , , , , , , , , ,  ]

Whereas this code produces an array of 20 elements which are all 3s:

> Array(20).join(' ').split(' ').map(function() { return 3; })
[ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 ]

Why does the first approach not behave as expected?

Robz
  • 1,703
  • 4
  • 20
  • 34

0 Answers0