繁体   English   中英

如何在地图中获取第一个数组索引的迭代?

[英]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};
    });
});

在上面的代码中,j是二级索引。

例如:

curveData[i][j]

我正在进行j迭代但是如何访问i迭代?

要获取外部索引,只需在顶级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};
    });
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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