问题
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