简体   繁体   中英

Get Immediate Child Property in Javascript Object

I am working with a minimally documented API. The response returns an object and, within that object, I have data I need...

ie

response: {
   locations: {
      location: {
         21421: { <-- this is random
           ...data needed in here
         }
      }
   }
}

The 21421 property appears to be a random number. I have no idea why, again, the documentation is very sparse. Is there any way to get the immediate child property of the response.locations.location ? If so, that would greatly help me.

Thanks!

You can iterate over it using for...in

for(var prop in response.locations.location) {
    console.log(response.locations.location[prop])
}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM