如果我有nested array
以下内容:
var attendees={attendees :[{name: John},{name: Terry}]}
如何使用forEach
函数在名称中循环?我试过了:
attendees.forEach(function(attendees){
console.log(attendees.name):
});
但是它不会遍历子数组,而只是给我:
[{name: John},{name: Terry}]
感谢帮助!
与另一个foreach,当检测到数组时:
attendees.forEach(function(attendee){
if(attendee.isArray()) {
attendee.forEach(function(subattendee) {
console.log(subattendee):
});
}
});
小心嵌套变量。对于已读数组和函数赋值变量,您具有相同的名称。
祝你好运
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句