ReactJS map through Object

前端 未结 8 2120
别跟我提以往
别跟我提以往 2021-01-31 16:53

I have a response like this:

I want to display the name of each object inside this HTML:

{subjects.map((item, i) => (
  
  • 8条回答
    •  走了就别回头了
      2021-01-31 17:30

      Use Object.entries() function.

      Object.entries(object) return:

      [
          [key, value],
          [key, value],
          ...
      ]
      

      see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries

      {Object.entries(subjects).map(([key, subject], i) => (
          
    • key: {i} Name: {subject.name}
    • ))}

    提交回复
    热议问题