I'm using the NASA Near Earth Object array for a student project and am having trouble accessing nested objects that have a date and hyphens for a key e.g.
2016-09-08 : [...]
The error I get back is just 'undefined'.
The API call I have is:
$(document).ready(function NASAtest() {
$.ajax({
type: "GET",
url: "https://api.nasa.gov/neo/rest/v1/feed?start_date=2016-09-07&end_date=2016-09-08&api_key=DEMO_KEY",
asynch: false,
contentType: "application/javascript",
dataType: "json",
success: function(data) {
console.log(data)
var recordList = data.near_earth_objects;
console.log(recordList);
var recordList2 = data.near_earth_objects[2016-09-08];
console.log(recordList2);
}
});
});
Sample API data:
{
"near_earth_objects": {
"2016-09-08": [
{
"neo_reference_id": "3726710",
"name": "(2015 RC)",
"nasa_jpl_url": "http://ssd.jpl.nasa.gov/sbdb.cgi?sstr=3726710",
"absolute_magnitude_h": 24.3,
"is_potentially_hazardous_asteroid": false,
} ] } }
See fiddle: https://jsfiddle.net/lollyborch/v640ocfr/
and JSON data: https://api.nasa.gov/neo/rest/v1/feed?start_date=2016-09-07&end_date=2016-09-08&api_key=DEMO_KEY
I'd eventually like to iterate over all the date info to get down to the keys like "absolute_magnitude_h" and "is_potentially_hazardous_asteroid" for a date range but at this stage am just having trouble getting past the date key.
I've tried using square brackets rather than dot notation as described here and here but can't seem to see what I'm doing wrong.
Any ideas on the right direction would be much appreciated.