将数据附加到JSON元素

时间:2014-01-19 15:39:04

标签: jquery json

我有一些JSON数据。例如:

["Test1","Internet Explorer 4.0","Win 95+","4","X","X"],
["Test2","Internet Explorer 4.0","Win 95+","4","X","Y"]

我想要的是为每个元素添加另一个“值”。例如:

["Test1","Internet Explorer 4.0","Win 95+","4","X","X", "NEW1"],
["Test2","Internet Explorer 4.0","Win 95+","4","X","Y", "NEW2"]

我尝试了很多东西,却无法让它正常工作。

apend()添加了一个全新的元素,因此无效。

这样做的正确方法是什么?

1 个答案:

答案 0 :(得分:1)

使用Array.push函数添加新元素:

var data = [["Test1","Internet Explorer 4.0","Win 95+","4","X","X"],
            ["Test2","Internet Explorer 4.0","Win 95+","4","X","Y"]];
for (var i = 0; i < data.length; i++) {
   data[i].push('NEW' + (i + 1));
}