I need help writing a loop to parse through a nested number array.
The JSON file I am working with contains event dates represented by number keys. Click here for the JSON reference for startdate and end date enter image description here
Below is the JavaScript code snippet that loops through each var i = 1 or j = 1. I want to parse through the entire nested numbers from dates and store them in a variable.
$(document).ready(function () {
$.getJSON('http://app.toronto.ca/cc_sr_v1_app/data/edc_eventcal_APR?limit=500', function (data) {
var data = data;
var i = 2;
var obj = data[i].calEvent;
var bingname = obj.eventName;
var j = 1;
var startdate = obj.dates[j].startDateTime;
var time = new Date(startdate);
var starttime = time.getFullYear()+'-' + (time.getMonth()+1) + '-'+time.getDate();
var name = JSON.stringify(bingname);
document.getElementById("bingname").innerHTML = name;
document.getElementById("bingtime").innerHTML = starttime;
var name = firebase.database().ref("/bing").set({
EventName : name,
EventStart : starttime
});
});
});
I need assistance implementing an incremental loop for var j. I'm having trouble because the json retrieved in obj.dates[j] does not appear to be an array. I cannot read it as a list of numbers to iterate through. Any help would be greatly appreciated.
If someone can even help me sort these dates from nearest to furthest from today, that would be genius:)