i am trying to enrich an array with the data that I load from a text file. With the first request I get the data that holds the URL to a text file. Now from that text file I would like to take the first line and add that to an new array. This works. However i would like to add the data from the original request as well. I can't seem to combine the both together. This is what I got in code so far:
var NewArray = [];
$http({
method: 'Get',
url: "https://xxx.azurewebsites.net/api/files/"
})
.success(function (data) {
for (var i = 0; i < data.length; i++) {
var x = data[i].Url;
$.when(GetFile(x))
.done(function (a1) {
var allLines = a1.split("
");
var lineOne = allLines[0];
NewArray.push({
Name: data[i].Name,
Url: data[i].Url,
text: lineOne,
})
});
};
function GetFile(x) {
return $.ajax({
method: 'Get',
url: x,
success: function (data) {
//console.log(data);
}
});
}
console.log(NewArray);
});
the error I get is TypeError: Cannot read property 'Name' of undefined. It can't find the data[i].Name and data[i].Url when i push to a new array and end's up 'undefined' How can I solve this?