DEV Community

Discussion on: 2 Ways to Merge Arrays in JavaScript

Collapse
 
thomas_graf profile image
Thomas Graf

Maybe it's a little bit longer, but you don't have to create an array just to use the prototypes concat method.

Instead of

[].concat([1,2],[3,4])

you could also write that one:

Array.prototype.concat([1,2],[3,4])
Collapse
 
samanthaming profile image
Samantha Ming

nice, thanks for sharing that 👍

Collapse
 
thomas_graf profile image
Thomas Graf

Just for fun I tried it on jsperf and the first one is way faster. Never thought that. But it's probably just a micro optimization.

jsperf.com/empty-array-conact-vs-p...