var dicList = [{
  student_id: 334,
  full_name: "student B",
  score: 9,
  class_id: 222
}, {
  student_id: 333,
  full_name: "student A",
  score: 7,
  class_id: 222
}]

for (var i = 0; i++; i < dicList.length) {
  for (var key in dicList[i]) {
    if (test.hasOwnProperty(key)) {
      console.log(key, dicList[i][key]);
    }
  }
}


当前返回未定义,我希望它返回每个字典中每个属性的值列表

最佳答案

你需要


condition statement的最后两个部分(final-expressionfor部分)夹在中间,并且

for ([initialization]; [condition]; [final-expression])
    statement

检查dicList[1]而不是test




var dicList = [{ student_id: 334, full_name: "student B", score: 9, class_id: 222 }, { student_id: 333, full_name: "student A", score: 7, class_id: 222 }]

for (var i = 0; i < dicList.length; i++) {     // move i++ to the end
    for (var key in dicList[i]) {
        if (dicList[i].hasOwnProperty(key)) {  // use dicList[i] instead of test
            console.log(key, dicList[i][key]);
        }
    }
}

10-08 11:39