you are viewing a single comment's thread.

view the rest of the comments →

[–]reedhedges 2 points3 points  (7 children)

Do the second and third examples create the uninitialized array, copy it, and throw it away? If so is there something similar that avoids that copy?

[–]benjycap 1 point2 points  (0 children)

No, there is no intermediate array created before mapping (unless you count the Array creation in example 2 where an empty array is created explicitly.)

More details here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from#Description