I'm not sure what you mean with the callback hell method. But you're using a callback (the function supplied as a parameter) in the query()
call. That function is only being called whenever query()
's body calls it. Making it behave asynchronous.
Problem now is, is the console.log
is outside this 'async-loop' and ran sequentially. So data['main']
is actually undefined by the time console.log
is called.
To fix it do this:
var data=[];
sequelize.query("SELECT `name`,`mobile` FROM `emp_table` LIMIT 0,50",function(result){
data['main']=result;
console.log(data['main']);
});
Move console.log
into the callback.