c-andrews's avatar

Map loop index

Hi, I am new to Laravel and diving into the deep end. I am trying to do something which I was hoping was going to be basic but I'm stuck.

I am using React with Inertia to display my content from Laravel. I have a simple Index.jsx file which is displaying all of the "Events" in my DB.

I am currently using this to create my Event Component: {events.map(event => <Event key={event.id} event={event} /> )}

This displays into a table so what I am trying to do is get the index so that i can change the highlight on each row. Is there an easy way to do this? What am I missing?

Thanks in advance

0 likes
2 replies
Sergiu17's avatar
Sergiu17
Best Answer
Level 60

if I got it right, then

// second parameter to the callback function is index
events.map( (event, index) => ...
c-andrews's avatar

Thanks I knew it had to be something simple.

Please or to participate in this conversation.