const potatoes = [
{weight: 100, id: 1},
{weight: 130, id: 2},
{weight: 124, id: 3},
{weight: 137, id: 4},
{weight: 184, id: 5},
{weight: 284, id: 6},
{weight: 190, id: 7},
{weight: 146, id: 8},
{weight: 164, id: 9},
{weight: 283, id: 10},
{weight: 172, id: 11}
]
- forEach语句:
potatoes.forEach((potato, index, arr) => {
potato.weight += 100
})
console.log(potatoes)
- map语句
const potatoesWeight = potatoes.map(potato => potato.weight)
console.log(potatoesWeight)
- reduce语句:
const totalWeight = potatoes.reduce((sum, potato) => sum += potato.weight, 0)
console.log(totalWeight)
- some语句:
const hasBigPotato = potatoes.some(potato => potato.weight >= 250)
console.log(hasBigPotato)
- every语句:
const isAllBigPotato = potatoes.every(potato => potato.weight >= 250)
console.log(isAllBigPotato)
- fliter语句:
const bigPotatoes = potatoes.filter(potato => potato.weight >= 250)
console.log(bigPotatoes)
- find语句;
const bigPotato = bigPotatoes.find(potato => potato.weight >= 250)
console.log(bigPotato)
- findIndex语句:
const bigPotatoIndex = bigPotatoes.findIndex(potato => potato.weight >= 250)
console.log(bigPotatoIndex)
dIndex(potato => potato.weight >= 250)
console.log(bigPotatoIndex)