This script transposes from an array with n rows x m columns to the array with m rows x n columns. In this script, you can use array of n != m
.
array = [
[a1, b1, c1, d1, e1],
[a2, b2, c2, d2, e2],
[a3, b3, c3, d3, e3],
[a4, b4, c4, d4, e4],
[a5, b5, c5, d5, e5],
[a6, b6, c6, d6, e6],
[a7, b7, c7, d7, e7],
[a8, b8, c8, d8, e8],
[a9, b9, c9, d9, e9],
[a10, b10, c10, d10, e10]
]
var result = [];
for (i in array[0]){
result.push(array.map(function(e,j){return e[i]}));
}
result = [
[a1, a2, a3, a4, a5, a6, a7, a8, a9, a10],
[b1, b2, b3, b4, b5, b6, b7, b8, b9, b10],
[c1, c2, c3, c4, c5, c6, c7, c8, c9, c10],
[d1, d2, d3, d4, d5, d6, d7, d8, d9, d10],
[e1, e2, e3, e4, e5, e6, e7, e8, e9, e10]
]