I have a question, how can i get a variable value (in my example array variable) outside of a callback function? Here is my code!
var Db = require("../database/databaseInit");
var array = [];
class DBManager{
getUsers() {
Db.find({}, function (err, users) {
users.forEach(function (element) {
array.push(element.username);
console.log(array) //here prints the users that i have in DB file
});
});
console.log(array) // but here prints []
return array;`enter code here`
}
}