0

I have an object with array properties that I am getting from Mongodb database. The backend setup is correct because I am able to get the output in console. But I am making some mistake in displaying this data in the desired table format.

{Array.isArray(lights)
                ? Object.values(lights).map((light, key) => (
                    <TableRow
                      key={key}
                      sx={{ "&:last-child td, &:last-child th": { border: 0 } }}
                    >
                      <TableCell>{light.name}</TableCell>
                      <TableCell>{light.status}</TableCell>
                    </TableRow>
                  ))
                : null}

This is the structure of the object I am getting in consoleScreenshot of console.log

How to I get the values of name and status rendered in the table using map function?

Anushka
  • 13
  • 6
  • Does this answer your question? [How can I access and process nested objects, arrays, or JSON?](https://stackoverflow.com/questions/11922383/how-can-i-access-and-process-nested-objects-arrays-or-json) – VLAZ Apr 14 '23 at 05:27

1 Answers1

0

Object.values ​​- not needed here:

Array.isArray(lights) ? lights.map((light, key) => ( ...
MaxAlex
  • 2,919
  • 1
  • 14
  • 14