loading...

re: 2 Ways to Merge Arrays in JavaScript VIEW POST

FULL DISCUSSION
 

Surprisingly concat is way faster. Doing any type of spread is 91% slower. jsperf.com/concat-vs-spreader/1

Edit: Actually, it seems to depend on the size of the array. With 10 elements in each array spread is faster. With 100 elements in each array spread is about 75% slower.

 

Interesting, thanks for writing out the test! Good to keep in mind if you need to optimize the code. But I wonder as spread become more popular, if the browser will start optimizing it ... maybe concat is faster because it’s been around longer and the browser is deciphering it πŸ€”

 

I wondered that too. You would think it would just call concat internally. I'm not sure what would cause the huge difference.

code of conduct - report abuse