【发布时间】:2013-04-04 09:12:02
【问题描述】:
我有这样的对象。
foo = {
0 : {
'bar' : 'baz',
'qux' : 'quux',
'this' : { 'hello' : 'yes' } // this is the object I want to extract
}
1 : {
'bar' : 'baz',
'qux' : 'quux',
'this' : { 'hello' : 'yes' } // extract
}
2 : {
'bar' : 'baz',
'qux' : 'quux',
'this' : { 'hello' : 'yes' }, // extract
'that' : { 'hello' : 'no' } // extract
}
}
使用这样的 for 循环,我可以遍历每个对象:
for(var i in foo){
...
}
问题是我只想从第三个和更大的子对象中提取数据,而不是每个对象中的 ('this') 。
【问题讨论】:
-
对象属性没有排序。请改用数组。
-
对象是无序的。实际上并没有“第一”或“第二”键值对的概念。您是否只是想获取碰巧具有对象值的所有键?
-
如果我一直都知道他们会按这个顺序来?
-
使用这种格式和常规的
for循环:foo = [{},{},{}] -
@Philip:没有没有顺序。这就是它们的显示方式。
标签: javascript object for-loop