📜  js 数组 mdn 中的最大数量 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:04.745000             🧑  作者: Mango

代码示例3
// For large data, it's better to use reduce. Supose arr has a large data in this case:
const arr = [1, 5, 3, 5, 2];
const max = arr.reduce((a, b) => { return Math.max(a, b) });

// For arrays with relatively few elements you can use apply: 
const max = Math.max.apply(null, arr);

// or spread operator:
const max = Math.max(...arr);