I'm trying to get a object but the key value is 0 so I keep getting an error when I try to access it.
locations: Object
0: Object
1: Object
I've tried doing locations["0"]
and locations.0
but none of those work. I just get undefined
when I try to see the object in the console.
What am I doing wrong?
locations.0
is a syntax error, as only valid identifiers can follow the dot. Both locations["0"]
and locations[0]
should work equally well. If they do not display the value you expect, make sure there is no change to the object; note that the default console printing method is not synchronous unless you print a string (ie if you're doing console.log(locations); locations[0] = "foo"
, you will likely see 0: "foo"
in your console output).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.