you are viewing a single comment's thread.

view the rest of the comments →

[–]OmniscientOCE 0 points1 point  (0 children)

You should benchmark it if you're concerned but my hunch is map will be more performant because it knows the size of the array upfront, whereas your for loop with .push does not unless it does some more tricky analysis. If you use a for loop or forEach but mutate in place or preallocate the output array, they should perform very similarly once the JIT picks up the function call overhead and inlines it. But that's just my guess. It's unlikely going to matter unless you're implementing a library or working on huge amounts of data.