Receiving JSON response like this
responses = {
"http://www.example.com/firts": {
error: [object Object],
response: [object Object],
body: [object Object]
},
"http://www.example.com/second": {
error: [object Object],
response: [object Object],
body: [object Object]
},
"http://www.example.com/third": {
error: [object Object],
response: [object Object],
body: [object Object]
}
}
var urls = ["http://www.example.com/firts", "http://www.example.com/second", "http://www.example.com/third"];
It works fine in for loop like this:
for(url in responses) {
var response = responses[url];
console.log('Got the response '+response.response.statusCode);
}
But I am not able to access it outside for loop. Tried:
var response = responses[urls[0]];
console.log('Got the response '+response.response.statusCode);
and
var response = responses["http://www.example.com/firts"];
console.log('Got the response '+response.response.statusCode);
and
var response = responses[0][urls[0]];
console.log('Got the response '+response.response.statusCode);
But nothing worked for me.