ReactJS map through Object

前端 未结 8 2121
别跟我提以往
别跟我提以往 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:11

      You get this error because your variable subjects is an Object not Array, you can use map() only for Array.

      In case of mapping object you can do this:

      { 
          Object.keys(subjects).map((item, i) => (
              
    • { subjects[item].name }
    • )) }

    提交回复
    热议问题