Adding two arrays | SoloLearn: Learn to code for FREE!


Adding two arrays

What's the point of using an add "+" operator instead of concatenation method on arrays. There a lot of examples in JavaScript coding challenges.For me it's useless.

11/12/2019 7:06:58 PM

Vladyslav Semeniuk 🐸

3 Answers

New Answer


According to MDN web docs “it is strongly recommended that the assignment operators (+, +=) are used instead of the concat() method.” According to performance tests, the assignment operators are several times faster.


Michael but last and first elements are merging into one and, as a result, you need to do additional operations to separate them.


Sorry, I misread your question. You can’t use the + operator for concatenation of arrays. The + operator performs a type conversion. It converts all arrays to strings. So the result of [1,2,3] + [4,5,6] would not be an array anymore. Only the concat method or the spread operator are suitable for merging arrays.