I do realize the title of this question is awkwardly chosen and I'll gladly change it towards something more descriptive if anybody has a suggestion, I just don't know how to describe it differently.
I have this bit of javascript code which is creating a json object containing an array labeled trips. Each object in this array contains an array labeled nodes, which I'd hope to contain objects with all the specific nodes of a trip.
var json = {origin: data.origin.name, destination: data.destination.name, trips: []};
for (var i = 0; i < data.trips.length; i++) {
var departure = data.trips[i].dep.time;
var arrival = data.trips[i].arr.time;
var trip = {departure: departure, arrival: arrival, nodes: []}
for (var j = 0; j < data.trips[i].legs.length; j++) {
trip.nodes.push({test: 'test'});
}
json.trips.push(trip);
}
The outcome looks like this.
{ origin: 'Dresden, Helmholtzstraße',
destination: 'Dresden, Zellescher Weg',
trips:
[ { departure: '12:04',
arrival: '12:26',
nodes: [Object] },
{ departure: '13:02',
arrival: '13:11',
nodes: [Object] } ] }
The array I'm pulling the data from, the one the second for loop loops through, contains several elements. So I'd expect to see the test object a few times inside the nodes array. I don't quite understand how to interpret what I'm getting though. Is it an array containing an unspecified object? And if so, why?
.toString()method returns when logging to console. If you run in browser console you'll be able to navigate the object with a mouse.