我有一个 map 函数来重复动态地创建组件。假设是这样的:
renderBoxes() {
return Array.map(data => this.myFunction(indexOfThisArray));
}
如何传递数组的索引?这样“myFunction”函数每次调用时都会获取索引值。
最佳答案
Map 提供第二个参数作为当前元素的索引,第三个参数作为整个数组本身。
renderBoxes() {
return Array.map((data, index, array) => this.myFunction(index));
}
了解更多关于Array.prototype.map的信息
关于javascript - React Native - 如何在 map 函数中传递索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46042268/