0

I do not see the error to access a property of this object:

console.log(routes);
[Object { bounds=((-34.76335, -58.21068), (-34.749880000000005, -58.202540000000006)),  copyrights="Datos de mapas ©2016 Google",  legs=[1],  más...}]
console.log(routes.legs);

undefined

or console.log(routes["legs"]);

is similar: undefined

What am I doing wrong? Thanks

dblanco
  • 285
  • 1
  • 8
  • 23
  • actually, i do not see, how your object/array??? look like. maybe you do something like this with your object and add the text, you get: `document.write('
    ' + JSON.stringify(object, 0, 4) + '
    ');`
    – Nina Scholz Apr 02 '16 at 17:14
  • 3
    `routes` appears to be an array containing a single object ? Try `routes[0]["legs"]` – guest271314 Apr 02 '16 at 17:14
  • 2
    `routes` is an array _containing_ an object. Do `routes[0].legs`. – Akshat Mahajan Apr 02 '16 at 17:15
  • Possible duplicate of [Access / process (nested) objects, arrays or JSON](http://stackoverflow.com/questions/11922383/access-process-nested-objects-arrays-or-json) – JP. Aulet Apr 02 '16 at 17:17
  • What is expected result of `((-34.76335, -58.21068), (-34.749880000000005, -58.202540000000006))` ? – guest271314 Apr 02 '16 at 17:22

1 Answers1

0

As your console printed out, routes is an array containing an Object, so you could try adding an index before selecting a key in the object. So, for example:

console.log(routes[0]["legs"]);
// or
console.log(routes[0].legs);
boxHiccup
  • 128
  • 8