Home > OS >  How can I access the first property of a nested property?
How can I access the first property of a nested property?

Time:08-11

enter image description here

Every pages property has a first property with a random name. How can I access this property?

I thought about pages[0] but it's not an array.

I'm dealing with an API.

CodePudding user response:

Use Object.values() to convert the object to an array, then get the first value.

Object.values(pages)[0]

CodePudding user response:

As long as there is only one nested object, you can use this to get the driver object.

pages[Object.keys(pages)[0]]
  • Related