Home > Net >  How to map array of objects
How to map array of objects

Time:09-16

I have some problems mapping an array of objects in JS.

This is how the response looks in my console:

[{...}]

...and when I expand it I get this:

0:{id:0, document:{...}} 1:{id:1, document:{...}}

Usually the response I get is always without this number in front of each object, like this:

{id:0, document:{...} {id:1, document:{...}

I tried every approach I know and I cant't manage to handle it.

The goal is to take each value out of "document" property and dynamically display it in some kind of table.

CodePudding user response:

This is the way the browser devtools decides to display the array, but it is actually correct, if I'm not mistaken you're still dealing with an array.

You can verify this by logging the following:

(Replace myVar with the variable name you chose for your response array)

console.log(Array.isArray(myVar)) If it outputs true then you're fine and you are dealing with an array.

  • Related