ISMAIL
ISMAIL

Reputation: 37

How to access the specific object in a nested array in java script

The screenshot of my code snippet.

I want to get the[items] Array object separately. My doubt is that the <value> object generated from the function return and due to <value> object it is not indexing properly.

I tried these approaches:

  1. views.value.items not working.
  2. views[0][items] not working.

Upvotes: 0

Views: 101

Answers (2)

user228011
user228011

Reputation: 561

views seems to be a Promise, that wraps the actual value you want. So you need to call the .then() method on it and provide a callback that can use the value that is inside the Promise. Or if you are in an async function, use await.

I would recommend to read at least the two following pages, that describe how to use promises in the two mentioned ways:

Upvotes: 1

Sabit Rakhim
Sabit Rakhim

Reputation: 458

As I understand views and value is an object. If so, you can use views.value.items[0]

It is better to check value type with console.log(typeof views)

Upvotes: 0

Related Questions