The concat method
With concat, we do not have to add even a single for...in loop. Instead, we can simply chain the concat method in the order we want!
1 | const array1 = [1, 2, 3]; |
Tip: Prefer starting with empty array when chaining
concat. In this way, it is clear that we make a new array and do not manipulate the existing ones! ^_^
Spread Operator (Since ES6)
With ES6 it is simple now! We can merge two or more arrays in one line:
1 | const array1 = [1, 2, 3]; |