How do I use the concat() method for multiple arrays? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How do I use the concat() method for multiple arrays?

13th Feb 2016, 2:18 PM
TheMachine
1 Answer
+ 1
`concat` takes as many parameters as you wish! `[1].concat([2],[3],[4]); // [1,2,3,4]`. If you have an array of arrays and want to concat them all, you can do ``` var arrays = [[1],[2],[3],[4,5]]; Array.prototype.concat.apply([], arrays); // [1,2,3,4,5] ``` But this is admittedly a bit of weird-looking javascript black magic.
25th Apr 2016, 9:48 PM
Schindlabua
Schindlabua - avatar