Given I have a JS object which gets is value from a mongodb database via mongoose using this function
const followed = await User.find(
{ _id: followie },
{
_id:0,"present": {
$in: [followerid, "$followers"],
}
}
);
When I console.log(followed), I get the following output
console.log(followed[0]);
/*output :
[nodemon] restarting due to changes...
[nodemon] starting `node index.js`
listening on port 8800 at time: 1655365344312
Mongodb Connected
{ present: true } ----------> console.log output */
but when I try to access the "present" object within the followed dictionary, I get the type undefined that is:
console.log(followed[0][0]);
/*output :
[nodemon] restarting due to changes...
[nodemon] starting `node index.js`
listening on port 8800 at time: 1655365532137
Mongodb Connected
undefined --------> this is the console.log() */
Upon using typeof(followed[0]) I get the type as an object but when I try to get the typeof[0][0] it gives me the type as undefined. Where am I going wrong ? I have also tried followed[0].present and followed[0][present] with same results
Via Active questions tagged javascript - Stack Overflow https://ift.tt/Lsq4CA9
Comments
Post a Comment