Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native - How to pass index in map function

I have a map function to create a component repetitively and dynamically. Suppose it's like this:

renderBoxes() {
    return Array.map(data => this.myFunction(indexOfThisArray));
} 

How can I pass the index of the array? So that the 'myFunction' function gets the index value everytime it is called.

like image 548
prasang7 Avatar asked Jul 15 '26 20:07

prasang7


1 Answers

Map provides second argument as the index of the current element and third argument as the whole array itself.

renderBoxes() {
    return Array.map((data, index, array) => this.myFunction(index));
} 

Read more about Array.prototype.map

like image 159
Raghav Garg Avatar answered Jul 17 '26 13:07

Raghav Garg