I want my data to be sorted as i can see the pokeparser function gives a url every time but getJson is executed after the end of the loop, how can it be done at the same time?
let counter = 151;
for(let i = 1; i <= counter; i++){
let url = `https://pokeapi.co/api/v2/pokemon/`;
url = url + i;
//console.log(url);
poke_parser(url);
}
function poke_parser(url){
console.log("before "+ url); ///////////////////////////////in that time i is taxionomicly
///////when the loop finished go to get Json
jQuery.getJSON(url,function(data){
console.log("after "+ url);
//////////////////////////instead executed after the loop
////////// What can i do?
// .......................
});
}
This is because
getJSONis asynchronous and by the time the first response comes back the loop is already over.But if your intention is to process a response only after the previous has been processed then you can use this technique: