flights.forEach(function(flight) {
var origin = flight.origin,
destination = flight.destination,
count_airport = +flight.count,
var z = "";
for (i in ListByAirline) {
z = i + '_count';
ListByAirline[i] = flight[z];
};
data_series_1[origin] = ListByAirline;
});
I am having problems with the for loop. For some reason all my elements in data_series_1 are just being mapped to the last iteration. Can anyone help?
To clarify - here are the inputs/outputs:
data_series_1 = {},
ListByAirline = {
'AA' : [],
'AS' : [],
'B6' : [],
'DL' : [],
'EV' : [],
'F9' : [],
'MQ' : [],
'OO' : [],
'UA' : [],
'US' : [],
'VX' : [],
'WN' : []
};
Flight data looks like this:
0: Object AA_cancelled: "" AA_count: "" and so on...
The output for the data_series_1 is:
ALB: Object AA: "" AS: "" B6: "" DL: "" EV: "" F9: "3" MQ: "" OO: ""
UA: "" US: "" VX: "" WN: ""
For EVERY origin (key)...so it is not iterating throughout and assigning the correct values to all the keys