我是 jquery 新手,正在尝试一些东西,但陷入困境, 我的问题是我有一个带有数组的对象,我无法找到从对象访问该数组的方法
//My object is shown in debugging time is as below
cache:object
0001-:Array[2]
0:value1,
1:value2
_prto_:object
并且我想从该对象的 0001-
数组访问 value1
和 value2
是否有方法访问该数组。任何帮助都会很棒。我知道使用 $.each
我可以循环遍历它,然后再次访问该数组,但是还有其他方法可以做到这一点。
最佳答案
您可以像这样访问它,并记住您应该使用 bracket notation
在这种情况下,因为您的键的起始字符为 number
.
cache['0001-'][0] //first element on that array
cache['0001-'][1] //second element
针对您的新要求的解决方法,
var cache = {'0001-' : [0,1]};
var xKeys = Object.keys(cache);
console.log(xObj[xKeys[0]][0]);
console.log(xObj[xKeys[0]][1]);
关于javascript - 如何访问数组对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21250113/