I want to update ans object inside the fetchAll() functions and then send it back after successful updation. But the response I get is '[]'.
var ans = []
Country.fetchAll(newdate,(err, data) => {
if (err)
res.status(500).send({
message:
err.message || "Some error occurred while retrieving data."
});
else ans.push(data);
});
State.fetchAll(newdate2,(err, data) => {
if (err)
res.status(500).send({
message:
err.message || "Some error occurred while retrieving data."
});
else ans.push(data);
});
res.send({ status: 201, data: ans });
How do I update the ans array inside the functions?