简体   繁体   中英

How can I get the iteration of the first array index in a map?

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?

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};
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM