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
Post a Comment