I am trying to get the _id from the objects within an array.
[ { _id: 5ba49c6304daff5034e6fa6a,
email: '[email protected]',
active: true,
events: [ [Object], [Object], [Object] ],
name: { first: 'editor', last: 'editor' } } ]
Each object within events array contains a _id. I need to get those ids in another array.
if (userobj.events) {
if (userobj.events[0]) {
var eIds = [];
for (var i = 0; i<userobj.events.length; i++) {
console.log(userobj.events._id);
eIds.push(userobj.events._id);
}
andArr.push({"_id":{"$in":eIds}});
}
}
I am getting undefined for each _id.
Any help is highly appreciated.
userobj.events[i]._id.eventsproperty objects contain_idproperty? If it contains just usefor (var i = 0; i < userobj.events.length; i++) { console.log(userobj.events[i]._id); }