我必须在asp.net中制作动态图表。为此我需要这种类型的数据结构: - [[0,0,8],[0,1,2],[0,2,7]数组内的数组,
我使用过array.push,但是将我的数据集转换为这种格式:
'for (var i = 0; i < forth.length; i++)
{
result.push([present2[i], present1[i], present3[i]]);
}
[0, 0, 8, 0, 1, 2, 0, 2, 7].'
我有3组数组:present2,present1,present3 &#39; present2: - [0,1,2,3,4,5] 存在1: - [0,1,2,0,1,2] present3: - [8,2,7,1,4,2]&#39;
现在我想用它们创建这种类型的结构 &#39; [[0,0,8],[0,1,2],[0,2,7]]&#39; 我怎么能这样做?
答案 0 :(得分:1)
var present2=[0,1,2,3,4,5], present1=[0,1,2,0,1,2] ,present3=[8,2,7,1,4,2];
var result=[];
for (var i = 0; i < present2.length; i++)
{
result.push([present2[i], present1[i], present3[i]]);
}
console.log(result);
document.getElementById("output").innerHTML=JSON.stringify(result);
<div id="output"></div>
答案 1 :(得分:0)
您的代码看起来是正确的,或多或少。结果定义在哪里?
这有效:
var result = [];
for (var i = 0; i < forth.length; i++)
{
result.push([present2[i], present1[i], present3[i]]);
}