我是jquery的新手,正在尝试某些东西并被卡在它上面,我的问题是我有带数组的对象,但我找不到从对象访问该数组的方法
//My object is shown in debugging time is as below
cache:object
0001-:Array[2]
0:value1,
1:value2
_prto_:object
我想从该对象访问数组value1
并value2
从0001-
数组中访问该数组。任何帮助都会很棒。我知道$.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]);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句