I am fairly new to nodejs coding and ran into a problem where i can't get the items i can log in console into an array for processing from a for each loop which makes a url request.
The code here first gets a list of keys from a request which i then turn into names using another request in the for each loop.
I need to log the name list in an array where it says 'need an array here', here is my current code:
request('https://api2.ripaex.io/api/delegates/getNextForgers', function (error, response, body) {
if (!error && response.statusCode == 200) {
var jsonContent = JSON.parse(body);
var delegates = jsonContent.delegates;
for (i = 0; i < delegates.length; ++i) {
request(String('https://api2.ripaex.io/api/delegates/get?publicKey=' + delegates[i]), function (error, response, body) {
if (!error && response.statusCode == 200) {
var jsonContent2 = JSON.parse(body);
console.log(jsonContent2.delegate.username);
}
})
}
console.log('need an array here');
} else { console.log('Error: Could not retrieve the data') }
})