在javascript中将行数组更改为列数组

时间:2014-04-12 17:17:16

标签: javascript parsing

目前,我有一个行数组,但我想要一个列数组,因此我可以相互绘制数据。这是一些示例代码,我得到前两列的值;但是,它没有让最后一列正确。

var rows = ["tm","Adata","Bdata",
            0,-0.14,4.781,
            0.003,-0.153,4.781,
            0.006,-0.151,4.831,
            0.008,-0.137,4.831];

var date = new Array();
var A = new Array();
var B = new Array();

// loop through all rows
for (var i = 0; i < rows.length; i++) {
// this line helps to skip empty rows
if (rows[i]) {
    // our columns are separated by comma
    var column = rows[i].split(",");

    // column is array now 
    // first item is date
    date[i] = column[0];
    // second item is value of the second column
    A[i] = column[1];
    // third item is value of the second column
    B[i] = column[3];

}
}

1 个答案:

答案 0 :(得分:0)

更改

B[i] = column[3];

B[i] = column[2];

那应该是最后一栏。