Search code examples
javascriptdevelopment-environmentthunderbird

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.

Solution

  • 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: