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?

1
  • 2
    map does omit holes. Commented Aug 25, 2015 at 22:38

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.