Is there an easy way (like concat) to add an array to an array resulting in an array of arrays. For example, take these two arrays
var array1 = [1,2];
var array2 = [3,4];
and get....
var combineArray = [[1,2][3,4]];
?
Join Stack Overflow to learn, share knowledge, and build your career.
Is there an easy way (like concat) to add an array to an array resulting in an array of arrays. For example, take these two arrays
and get....
? |
||||
|
|||
|
Try this one
OR
|
||||
|
If you have two arrays and want to create an array of arrays you could write a simple function which takes an indefinite N number of arrays and reduces them to one array of N arrays. E.g:
Edited for a simpler solution:
If you want to flatten the two arrays, you can use ES6 destructuring synthax:
|
|||
|
Use the
|
|||
|
var combineArray = [array1, array2];
? – mylee 4 hours ago