Array.prototype.reduceintermediateconst nums = [3, 1, 4, 1, 5, 9]
nums.reduce((max, n) => n > max ? n : max, -Infinity)
// β 9Use reduce() to find the maximum value by updating the accumulator when a larger value is found.
You can find the maximum value in an array using reduce() β without Math.max.
[3, 1, 4, 1, 5, 9].reduce((max, cur) => cur > max ? cur : max, -Infinity) // 9