I have a multidimensional array which can contain a different number of arrays. What I want to do is to match all arrays in order of key not value, and produce a new array for each row created, something like this
var arr = [
[1,2,3,4,5],
[1,2,3,4,5],
[1,2,3,4,5],
[1,2,3,4,5]
]
The result I need
var arr = [[1,1,1,1],[2,2,2,2],[3,3,3,3],[4,4,4,4],[5,5,5,5]]
how can I achieve this?
const rotate = a => Object.keys(a[0]).map(c => a.map(r => r[c] ));- oh, wait, you don't want to rotate the array, you just want an array of arrays of the same value?[[1,2,3],[4,5,6],[7,8,9]]what output would you expect?const fn=a=>a[0].map((c, i)=>a.map(r=>r[i]));