// 获取最大值
let arr = [1, 2, 3, 4]
this.maxValue = arr.reduce(function (v1, v2) { return v1 > v2 ? v1 : v2 }, 0)
console.log('最大值', this.maxValue) // 最大值 4
reduce()快速获取数组中的最大值
最新推荐文章于 2024-05-08 21:02:03 发布
// 获取最大值
let arr = [1, 2, 3, 4]
this.maxValue = arr.reduce(function (v1, v2) { return v1 > v2 ? v1 : v2 }, 0)
console.log('最大值', this.maxValue) // 最大值 4