Totally I have 7 arrays . my first array contains only one item which has to be inserted to the 0th index of all other 6 arrays . while searching through questions related to this I found a.concat(b) will be better than a.unshift(b). Is there any other best way available to perform this function .
Asked
Active
Viewed 84 times
-3
-
1Posible duplicate of https://stackoverflow.com/questions/5080028/what-is-the-most-efficient-way-to-concatenate-n-arrays-in-javascript – Burdy Jul 23 '17 at 13:22
-
no probably not. – Jonas Wilms Jul 23 '17 at 13:40
2 Answers
0
Simplest way to merge multiple arrays:
var array1 = [1.79 , 2.33 , 3.1];
var array2 = [2];
var multipleArrays = [array1, array2];
var flatArray = [].concat.apply([], multipleArrays);
console.log(flatArray);

Milan Chheda
- 8,159
- 3
- 20
- 35
-
No i am not trying to merge multiple arrays together.. Just 2 arrays at a time – Karthi Jul 23 '17 at 16:57
-
Well, you merge 2 or merge many, you can use above snippet for it. – Milan Chheda Jul 24 '17 at 06:05
0
var array1=[1]
var array2=[2]
var array3=[3]
var array4=[4]
var array5=[5]
var array6=[6]
var array7=[7]
var concatedArray = array1.concat(array2).concat(array3).concat(array4).concat(array5).concat(array6).concat(array7);
console.log(concatedArray)

Vlado Pandžić
- 4,879
- 8
- 44
- 75