+ 1
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.
3 Respostas
+ 2
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.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat
0
Michael but last and first elements are merging into one and, as a result, you need to do additional operations to separate them.
0
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.