Reputation: 3758
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.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.
For example:
curveData[i][j]
I am getting the j iteration but how can I access the i iteration?
Upvotes: 1
Views: 49
Reputation: 36521
To get the outer index, you just need to include the index parameter in your top level map
:
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};
});
});
Upvotes: 3