In the following code curveData is a 2 dimensional array. How can I get the iteration of the first array index in a map?
在下面的代码中,curveData是一个二维数组。如何在地图中获取第一个数组索引的迭代?
curveData.map(function(d) {
return d.map(function(count, j) {
console.log('d:'+d+', j:'+j+', count:'+count);
return {x:j, y:count, y0:0};
});
});
In the code above j is the secondary index.
在上面的代码中,j是二级索引。
For example:
curveData[i][j]
I am getting the j iteration but how can I access the i iteration?
我正在进行j迭代但是如何访问i迭代?
1 个解决方案
#1
To get the outer index, you just need to include the index parameter in your top level map
:
要获取外部索引,只需在*映射中包含index参数:
curveData.map(function(d, i) {
return d.map(function(count, j) {
console.log(curveData[i][j]);
console.log('d:'+d+', j:'+j+', count:'+count);
return {x:j, y:count, y0:0};
});
});
#1
To get the outer index, you just need to include the index parameter in your top level map
:
要获取外部索引,只需在*映射中包含index参数:
curveData.map(function(d, i) {
return d.map(function(count, j) {
console.log(curveData[i][j]);
console.log('d:'+d+', j:'+j+', count:'+count);
return {x:j, y:count, y0:0};
});
});