js获取数组中的最小值和最大值的几种方法
js获取数组中的最小值和最大值的几种方法。
Math.max()配合扩展符
1 | let nums = [1, 6, 2, 8, 10, 11, 24, 3, 9]; |
Math.max()配合apply()
1 | let nums = [1, 6, 2, 8, 10, 11, 24, 3, 9]; |
Math.max()配合reduce()
1 | let nums = [1, 6, 2, 8, 10, 11, 24, 3, 9]; |
sort()排序
1 | let nums = [1, 6, 2, 8, 10, 11, 24, 3, 9]; |