gpt4 book ai didi

javascript - 使用 es2015 map 获取索引失败

转载 作者:行者123 更新时间:2023-12-03 04:25:56 25 4
gpt4 key购买 nike

{map(arr, (obj,index) => 
<div key={index}>{obj.name}</div>
</div>)}

我上面的jsx有什么问题吗?无法使用 map 获取索引?

最佳答案

这是使用 map 的正确方法。

array.map((x, index)=>{
return (<div key={index}>{x.name}</div>);
});

Array.prototype.map.call(arr, function(x, index) {
return (<div key={index}>{x.name}</div>);
});

Mozilla

Array.prototype.map()

关于javascript - 使用 es2015 map 获取索引失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43729583/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com