i have an object with function as below: since it is making an ajax call, it just returns the empty array. how do i return the data after the response.
var data = [];
var ApiUtil = {
fetchAll: function (resourceName) {
request
.get(url + resourceName)
.set('Accept', 'application/json')
.end(function (err, res) {
if(!err) {
data = res.body;
}else{
console.log('error');
}
});
return data;
}