Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Please, here is the updated code, with empty arrays and everything. It is in plain javascript so no library needed. Its jut a crude example I know, but it works and I hope it will help you to find your way.Later you can refine it.</p> <pre><code>var stops = { "Stops": [ { "Lat": 38.92092, "Lon": -77.043684, "Name": "COLUMBIA RD NW + MINTWOOD PL NW", "Routes": [ "42", "43", "H1", "L2" ], "StopID": "1001779" } ] }, predictions = { "Predictions": [ { "DirectionNum": "1", "DirectionText": "North to Mt Pleasant Via Adams Morgan", "Minutes": 7, "RouteID": "42", "VehicleID": "7136" }, { "DirectionNum": "1", "DirectionText": "North to Mt Pleasant Via Adams Morgan", "Minutes": 25, "RouteID": "42", "VehicleID": "7103" }, { "DirectionNum": "0", "DirectionText": "North to Chevy Chase Circle", "Minutes": 32, "RouteID": "L2", "VehicleID": "2207" }, { "DirectionNum": "1", "DirectionText": "North to Mt Pleasant Via Adams Morgan", "Minutes": 36, "RouteID": "42", "VehicleID": "7132" }, { "DirectionNum": "1", "DirectionText": "North to Mt Pleasant Via Adams Morgan", "Minutes": 58, "RouteID": "42", "VehicleID": "7111" }, { "DirectionNum": "1", "DirectionText": "North to Mt Pleasant Via Adams Morgan", "Minutes": 69, "RouteID": "42", "VehicleID": "7135" } ], "StopName": "Columbia Rd Nw + Mintwood Pl Nw" }; var routeTimes = {}; for (var index in predictions.Predictions) { if(!routeTimes.hasOwnProperty(predictions.Predictions[index].RouteID)) { routeTimes[predictions.Predictions[index].RouteID] = []; routeTimes[predictions.Predictions[index].RouteID].push(predictions.Predictions[index].Minutes); } else { routeTimes[predictions.Predictions[index].RouteID].push(predictions.Predictions[index].Minutes); } } var routes = stops.Stops[0].Routes, routesVsMinutes = {}; for(var i in routes) { if (!routesVsMinutes.hasOwnProperty(routes[i])) { routesVsMinutes[routes[i]] = {Minutes: []}; } if (routeTimes[routes[i]]) { routesVsMinutes[routes[i]].Minutes = routeTimes[routes[i]]; } } stops.Stops[0].Routes = routesVsMinutes; console.log(stops); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload