I have a function which takes Array of OKR ids and make backend call then return a formatted Array of object which has OKR id and title. But this process is asynchronous.
How can I make it synchronous so that it will fetch OKR id and title for first element of input array then only it will move to second element of Array. It should return the formatted array only after it has got the ids and title of all Array element.
var ExpandOkrData = function(okrArray){
var formattedOkr = [];
for(var i=0; i< okrArray.length;i++){
Okr.Individual.query({okr_id: okrArray[i]},function(data){
var okr = {};
okr.title = data.title;
okr.okr_id = data.okr_id;
formattedOkr.push(okr);
},function(e){
console.log(e);
});
}
return formattedOkr;
}
P.S.: Okr.Individual.query is a Angular JS Service.