Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
238 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...