Angular 嵌套for循环将不起作用。语法?

Angular 嵌套for循环将不起作用。语法?,angular,typescript,firebase,ionic2,angularfire2,Angular,Typescript,Firebase,Ionic2,Angularfire2,为什么这个代码不起作用?第二个循环中的console.log不会触发 this.afDatabase.list(`data/users/${this.currentUserID}/visits/`, ref => ref.orderByChild('type').equalTo('study')).snapshotChanges().map(changes => { return changes.map(c => ({ key: c.payload.key, ...c.pa

为什么这个代码不起作用?第二个循环中的console.log不会触发

this.afDatabase.list(`data/users/${this.currentUserID}/visits/`, ref => ref.orderByChild('type').equalTo('study')).snapshotChanges().map(changes => {
  return changes.map(c => ({ key: c.payload.key, ...c.payload.val() }));})
  .take(1).subscribe(data => {


  let studys1 = [];
  let studys2 = [];

  for (let i=0; i < data.length; i++) {
    studys1.push(data[i]);

    for(let j=0; j < data[i].length; j++) {
      console.log(data[i][j]); //This not fires. I see nothing in the console
      studys2.push(data[i][j]) // Neither...
    }
  }

  console.log('Parent Length: ' + studys1.length); // Works
  console.log('Child Length: ' + studys2.length); //Always 0

});
我想要获得的数据:

console.log“%O”,数据提供以下输出:


有什么想法吗?

迭代对象不同于迭代数组,您可以使用for-in来迭代对象:

for(var i in data){
  for(var j in data[i]){
    console.log(data[i][j]);
    studys2.push(data[i][j]);
  };
};

希望这有帮助。

console.log“%O”,通过提供数据的外观,数据将有所帮助。我使用您需要的console.log数据编辑了我的文章:数据项不是数组,而是对象。可以迭代对象,但它与数组迭代不同。只需搜索typescript对象迭代。是否要将年龄、国家、日期等值推送到studys2中?Object.keysobj可能会有帮助。不,我需要计算子对象。所以在上面的例子中,console.log'studys2.length'的结果必须是1..谢谢,这是一个进步。但我不需要对象子对象的所有数据。我只需要数一数那个孩子自己。所以在上面的例子中,console.log'studys2.length'的结果必须是1…@eleinad不知道我是否正确。您只需要第一个子密钥中的内容?在你的例子中,里面的内容-KyaYm…?不是内容,只是计数。说明:我需要知道以学习为类型的所有入口的计数。我有父入口和子入口。所以我需要所有的计数来建立总和。这就是全部:-所以你在一个数组中有对象,并且想要得到type=study的对象的数量,我得到的对吗?