如何在JavaScript或D3.JS中访问2D数组 [英] How do I access a 2D array in JavaScript, or D3.JS

查看:86
本文介绍了如何在JavaScript或D3.JS中访问2D数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从以下代码访问第二个数组中的数据:

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]];

我正在尝试使用以下功能访问"team""team number".

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.

我的问题是如何访问这些数组中的数据?

推荐答案

与访问外部数据的方式相同.

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

在用于访问它们的东西的末端贴[index].

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

这篇关于如何在JavaScript或D3.JS中访问2D数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆