function App() {
const users = [
{id: 1, name: 'John'},
{id: 2, name: 'Rusk'},
{id: 3, name: 'Erlic'}
]
return (
<ul>
{users.map((item, index) =>
<li key={index}>Index is: {index}. User is {item.name}</li>
)}
</ul>
);
}
Output
The minimal code that can be used to get the index inside the map() function is:
{users.map((item, index) =>
<li key={index}>Index is: {index}. User is {item.name}</li>
)}
In the map function, you can find the index as its second parameter.
0 Comments