Currently I am making an API call, and processing the response data as follows.
request.get('https://example.com', function(error, response, body) {
body = JSON.parse(body);
name = body.name
image = body.picture.data.url
userList[i].name = name;
userList[i].image = image;
console.log(userList[i])
}
After implementing this code block, it appears to be functioning well as the variables are visible in the array. However, when I attempt the following approach:
request.get('https://example.com', function(error, response, body) {
body = JSON.parse(body);
userList[i].name = body.name;
userList[i].image = body.picture.data.url;
console.log(userList[i])
}
And then try to print out the userList array, the name and image properties seem to be blank or not stored properly.
I am curious to understand why the information is not being stored correctly within the array?