For a student project, I'm utilizing the NASA Near Earth Object array but encountering difficulties accessing nested objects with date and hyphen keys like:
2016-09-08 : [...]
When trying to access these objects, I receive an 'undefined' error message.
Below is the API call I am making:
$(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);
}
});
});
Here is some 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,
} ] } }
Feel free to check out the fiddle link for more details: https://jsfiddle.net/lollyborch/v640ocfr/
You can also view the JSON data directly from the NASA API here:
My goal is to eventually iterate through all the date information to extract specific keys like "absolute_magnitude_h" and "is_potentially_hazardous_asteroid" within a given date range. However, my current roadblock lies in accessing the date key itself.
I've experimented with using square brackets instead of dot notation based on resources such as here and here, but I seem to be missing something crucial. Any guidance or insights on the right approach would be highly valuable.