当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - how can i loop through an array within an object?

问题描述:

I want to loop through an array of objects named tier1.

what I get is this:

TypeError: Cannot read property 'length' of undefined

My code looks something like this:

module.exports.getTier1= function(curUser, callback){

for (var i = 0; i < curUser.tier1.length; i++) {

var val = curUser.tier1[i];

console.log("index: " + i + " val: " + val);

}

};

var UserSchema = mongoose.Schema({

username: {

type: String,

index:true

},

password: {

type: String

},

email: {

type: String

},

name: {

type: String

},

tier1: [Tier1]

});

分享给朋友:
您可能感兴趣的文章:
随机阅读: