javascript - Loop through all elements of array inside array? -


i'm drawing blank doing wrong here. trying query array inside mongoose model , can't seem it. i'm sure simple.

my model looks this:

var aschema= new mongoose.schema({     usertype: string,     arr: [         {             id: number,             name: string,              description: string,             attribute: string,             answertype: string,             textanswer: string,             skill: [                 {                     heading: string,                     detail: string                 }             ]         }     ] }); 

i want loop through questions , print out name each record. tried following:

a.find({ "usertype": "test" }, { "arr": 1 }, function(err, users) {         if (err) {             console.log(err);         } else {             (i = 0; < users.length; i++) {                 console.log(users[i].name);             }         }     }); 

i keep getting undefined name, how can access name of each element in users array?

thank!

a.find({ "usertype": "test" }, { "arr": 1 }, function(err, users) {         if (err) {             console.log(err);         } else {             (i = 0; < users.length; i++) {                 console.log(users[i].arr[0].name);             }         }     }); 

should work


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -