Im having trouble to understand the scope of an array in javascript. Im working with mongoose on nodejs and im kinda new to this language. Can someone help me to understand what im doing wrong? Thanks
const User = require(‘../models/Users’);
const friends_ofMain = (main_id) => {
var friendsIds = [];
const look4Friends = User.findById(main_id, (err, result) => {
for (let i = 0; i < result.length; i++) {
friendsIds.push(result[i].friend_id);
}
return friendsIds;
})
}
module.exports = friends_ofMain;