0

How can I retrieve information from a JavaScript object that has a numeric value as an index?

"element_count": 69,
"near_earth_objects": {
"2016-10-29": [ ... ]

I need to access the data inside that "2016-10-29" Array.

I have no problem accessing the other elements like this:

$.getJSON(Call, function(data1){
    console.log(data1.element_count);
 });
Sergi
  • 1,192
  • 3
  • 19
  • 37

2 Answers2

1

Like this to mix notation and retrieve sub-array element in a property of your Json object :

var data = {
    "element_count": 69,
    "near_earth_objects": {
    "2016-10-29": ["subelement1", "subelement2", "subelement3"],
    "2016-10-30": ["subelement11", "subelement12", "subelement13"]
    }
};
console.log(data.near_earth_objects["2016-10-29"][1]);
kevin ternet
  • 4,514
  • 2
  • 19
  • 27
0

x = { 
  "near_earth_objects" : 
    { 
      "2016-10-29" : 1
    } 
}

console.log(x["near_earth_objects"]["2016-10-29"])
naortor
  • 2,019
  • 12
  • 26