0

我有这个 json 响应,其中 obj.attributes 列出了以下内容。我只想遍历每个对象,而这些对象又具有 ids ..我如何遍历对象并打印 id 属性

Object {0: Object, 1: Object, 2: Object, 3: Object, subject_Keys: "", schoolapplication: Object}

我试过了

for(var item in obj.attributes)
{
     var intRegex = /^\d+$/;
 if(intRegex.test(item)) {
       console.log(obj.attributes[item]["id"]) //This prints undefined
     }
}

编辑1:console.log(obj)

child {cid: "c33", changed: Object, attributes: Object, _changes: Array[0], _hasComputed: true…}
_changes: Array[0]
_changing: false
_currentAttributes: Object
_hasComputed: true
_pending: false
_previousAttributes: Object
app_id: 8
attributes: Object
changed: Object
cid: "c33"
__proto__: Surrogate

console.log(obj.attributes)

 Object {0: Object, 1: Object, 2: Object, 3: Object, subject_Keys: "", schoolapplication: Object}  
 0: Object
   name: "key1"
   schoolapplication: Object
   id: 3
   __proto__: Object
1: Object
2: Object
3: Object
__proto__: Object
4

1 回答 1

1

如果您为整个对象提供数据,那将很有帮助。但我知道我得到了这个解决方案

for(var item in obj)
{
    if(obj[item].hasOwnProperty('id')) {
        console.log(obj[item].id);
    }
}
于 2013-09-30T09:34:32.587 回答