2 回答

TA貢獻(xiàn)2011條經(jīng)驗(yàn) 獲得超2個(gè)贊
在這種情況下,map就足夠了。
const yo = {
one: {
value: 9,
mission: 17
},
two: {
value: 18,
mission: 6
},
three: {
value: 3,
mission: 4
},
}
const total = Object.values(yo).map(({ mission }) => mission);
console.log(Math.min(...total));

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超8個(gè)贊
0您將作為累加器 ie 的初始值傳遞t。0小于所有mission值。因此,您需要傳遞最大值 ieInfinity作為 的第二個(gè)參數(shù)reduce()。
const yo = {
one: {
value: 0,
mission: 17},
two: {
value: 18,
mission: 3},
three: {
value: -2,
mission: 4},
}
const total = Object.values(yo).reduce((t, {mission}) => Math.min(t, mission), Infinity);
console.log(total)
添加回答
舉報(bào)