I have read this Swap rows with columns (transposition) of a matrix in javascript However, it did not work for me (because I still stupi).
There are numbers of arrays each as individual colum like that:
id [1, 2, 3]
caption [one, two, three]
title [One, Two, Three]
I want to convert columns to row:
arr= [1, one, One]
...
Some code
var res = [];
for(i in this.fields) {
for(j in this.fields[i].value) {
res[j][i] = this.fields[i].value[j];
}
}
it give me "TypeError: can't convert undefined to object "
In php this method works fine, but could somebody point me how to do it in js. Thanks in advance.
UPDATE for simplication
var arr = [];
arr[0] = [];
arr[6][0] = 5;
/*
Exception: can't convert undefined to object
@Scratchpad/1:4
*/
When we scan common string we iterate with indexes like 0-0, 0-1, 0-2 until end-of-row when starts again 1-0 and so on. But here I need 0-0, 1-0, 2-0 end of col and again 1-0, 1-1, 1-1 ...
UPDATE for "this". Just add a cople of lines:
console.log(this.fields[i].value[j]);
console.log('indexes: i='+i, 'j='+j);
and as could you see there are no undefined values
4
indexes: i=0 j=0
1
indexes: i=1 j=0
1
indexes: i=2 j=0
one
indexes: i=3 j=0
One
indexes: i=4 j=0