-2

I have array in react like

[
{
  no:"s1",
  name:"abcd"
},
{
  no:"s1",
  name:"abcd"
}
]

I want to use map function to render in UI but. I want id to be increment with map integrations

eg

<ul>
   <li id="1">
     {no}
     {name}
   </li>
  <li id="2">
     {no}
     {name}
  </li>
</ul>
poo
  • 1,080
  • 3
  • 10
Aniket Thorat
  • 107
  • 2
  • 10

1 Answers1

0

you can just use array index for that

const data = [
{
  no:"s1",
  name:"abcd"
},
{
  no:"s1",
  name:"abcd"
}
]
...
return <ul>
  {data.map((item, i) => <li key={i} id={i+1}>{item.no} {item.name}</li>)}
</ul>
R4ncid
  • 6,944
  • 1
  • 4
  • 18