I use the node request ajax package. So, i have an loop, in every iteration it makes an request to my server.
// realItems needs the complete value of items assigned
var realItems;
var items = [];
_.forEach(JSON.parse(body), (value, key) => {
request('myurl/' + id, (error, response, body) => {
items = JSON.parse(body)
});
});
How can i bundle all my requests from request
package, so I can assign the value of items
variable to the realItems
at the end?
// edit:
I use react js, so in this case realItems
is an state, and i can't trigger it in every loop iteration, because render triggers on every setState