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.
Simply pass a second arguments to your arrow function
(data, index)
Signaure for
.map
Map provides second argument as the index of the current element and third argument as the whole array itself.
Read more about Array.prototype.map
the syntax of map is
source. You can find the index as the 2nd parameter in the callback function