How do I access a 2D array in JavaScript, or D3.JS

ぃ、小莉子 提交于 2019-12-12 06:51:13

问题


I want to access the data in the second array from the following code:

var data = [ ["Team 1", 3], ["Team 2", 6], ["Team 3", 9]];

I am trying to access the "team" and "team number" using the following functions.

_Chart._accessors = {
`"team": function(data) { return data[0]; },`
`"current": function(data) { return data[0]; }`    
};

When I check the console log team, and current return arrays of two items which is logical.

My question is how do I access the data inside those arrays?


回答1:


The same way as you access the data in the outside of them.

Stick [index] on the end of the thing you use to access them.

data[0][0] // for example
Chart._accessors.team()[0] // for another example


来源:https://stackoverflow.com/questions/23817081/how-do-i-access-a-2d-array-in-javascript-or-d3-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!