Answer the question
In order to leave comments, you need to log in
How to glue a multidimensional array so that the values from the subarrays go one by one?
Hello. Faced with a problem.
There is an array consisting of several subarrays equal in length to each other.
Example
var arr = [
[1,2,3,4,5],
[6,7,8,9,10]
];
var arr2 = [1,6,2,7,3,8,4,9,5,10];
Answer the question
In order to leave comments, you need to log in
head-on solution
var arr2 = [];
for (var i=0; i< arr[0].length; i++) {
for(var j=0; j<arr.length; j++) {
arr2.push(arr[j][i]);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question