javascript - JS 中的 Array(parameter).fill().map 是什么?
问题描述
import './Product.css'
function Product({ title, image, price, rating }) {
return (
<div className="product">
<div className="product__info">
<p>{title}</p>
<p className="product__price">
<small>$</small>
<strong>{price}</strong>
</p>
<div className="product__rating">
{Array(rating)
.fill()
.map((_, i) => (
<p></p>
))}
</div>
</div>
<img src={image} alt=' ' />
<button>Add to Basket</button>
</div>
)
}
export default Product;
好吧,我正在浏览一个项目的 Youtube 教程。我不明白该声明的{Array(rating).fill().map(_, i)=>(<p>*<p>))}
作用。我知道什么fill()
是单独做的,什么map()
是单独做的。但是我不明白_
map 函数中传递的参数。当我试图总结所有正在发生的事情时,我无法掌握正在发生的事情以及如何发生的事情。如果有人需要更多代码,请告诉我。谢谢你。
解决方案
推荐阅读
- python - 请检查有关“sort_values”的错误消息
- c++ - 模板基类函数成员的别名
- python - 我的 TCP 服务器只发送 b' ' 而不是腌制数据
- process - 进程数
- machine-learning - 如何将数据集识别为时间序列数据?
- javascript - 虽然 this.state 是一个 Javascript 对象,但为什么即使在将具有数据的状态传递给它之后状态为 null?
- yii2 - Yii2 : 在 appasset 中切换生产和开发版本脚本
- oracle - 创建 Oracle SQL Java 函数不起作用
- python - LD_preload 用于使用其他版本的 libc,在 pwntools 中不起作用
- drag-and-drop - 我想在角度 2 中使用 CDK 为 textarea 实现拖放功能,但它无法正常工作