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,131
  • 3
  • 15
  • 32

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,216
  • 2
  • 16
  • 25
0

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

console.log(x["near_earth_objects"]["2016-10-29"])
naortor
  • 1,961
  • 12
  • 23