// 使用 Math.max 和 spread 运算符取数组最大值
const numbers = [1, 3, 5, 7, 9, 2, 4, 6, 8];
const maxNumber = Math.max(...numbers);
console.log(maxNumber); // 输出: 9
// 解释说明:
// Math.max() 函数返回一组数中的最大值。
// 使用 spread 运算符 (...) 可以将数组元素展开为独立的参数传递给 Math.max()。
// 这样就可以轻松地从数组中找到最大值。
上一篇:js 数组查找元素
下一篇:js 数组取最大值
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站