3 回答

TA贡献1891条经验 获得超3个赞
您可以这样定义
var arr = [ [1,2,3],[4,5,6]];
arr.map(key=>console.log(key);)// here key itself will be an array..Loop through that to get your individual values.

TA贡献1853条经验 获得超9个赞
除了2D数组之外,您还可以将a Map,每个学院的编号用作键,并将数组用作其值。您可以分别使用get和set检索和更新特定键的值。
const map = new Map([
[0, [1,2]],
[1, [3,4]],
[2, [1,2,3]],
[3, [3,4,5]]
])
map.set(4, [10,20]) // to add a new value to map
console.log(map.get(1)) // to retrieve value, use "get"
console.log(map.get(3))
甚至一个对象都可以工作:
const obj = {
0: [1, 2],
1: [3, 4],
2: [1, 2, 3],
3: [3, 4, 5]
}
console.log(obj[0])
console.log(obj[2])
添加回答
举报