ok am starting on nodeJS and am stuck at this code, if i output inside the loop i get the array as i want, but if i do outside the loop it returns undefined.
question is: What is wrong with this?, thx in advance;
var array = [];
var temp = "";
var http = require("http");
for (var i = 2; i < 5; i++) {
http.get(process.argv[i],function(res){
res.setEncoding("utf8");
res.on("data",function(data){
temp += data;
});
res.on("end", function(){
array.push(temp);
console.log(array[0]);//this returns the array[0] OK NP;
temp = "";
});}
);
}
console.log(array[0]);//this returns undefined;