Next.js Discord

Discord Forum

Not sure how to loop through an array

Answered
Minskin posted this in #help-forum
Open in Discord
MinskinOP
Hi everyone! I have an interface that holds onto an array of information. I would like to loop through each of of them and call a function for each tab. I wasn't able to make anything online work though :/
Answered by Yi Lon Ma
you need to use .map instead to render list items
View full answer

10 Replies

MinskinOP
@Minskin Click to see attachment
the syntax of forEach is wrong
props.tabs.forEach(tab=>ContentTab(...))
@Yi Lon Ma the syntax of forEach is wrong
MinskinOP
forEach returns undefined
you need to use .map instead to render list items
Answer
MinskinOP
Do you perhaps have a link on the topic?
MinskinOP
Thanks :)
@Yi Lon Ma Awesome, it works now! Thank you for the help, I really appreciate it :)