使用 map 方法复制价格降低 25% 的产品数组并创建一个新变量

Using the map method make a copy of an array of products with prices reduced 25% and create to a new variable

const products = [
  {
    name: 'backpack',
    color: ['red', 'yellow'],
    price: 500,
  },
  {
    name: 'shirt',
    color: ['blue'],
    price: 400,
  },
  {
    name: 'shoes',
    color: ['red'],
    price: 1200,
  },
  {
    name: 'socks',
    color: ['yellow', 'blue'],
    price: 200,
  },
  {
    name: 'pants',
    color: ['blue', 'red'],
    price: 1000,
  },
]

All of the items are 25% off. Using a map method, make a copy of the array products with prices reduced by 25%, then save copy to a new variable called saleproducts.

const saleProducts = products.map( (element,) =>{
  return element['price'] + .25 / (element['price'] * 10000 )
})

我有这个,但我真正卡住的地方是价格的 25% 折扣。

试试这个:

products.map((product) =>({ ...product, price: product.price * 0.75 }));

P.D。读这个: