热门

最新

红包

立Flag

投票

同城

我的

发布
qq_35395195
MAVER1CK
3 年前
trueqq_35395195

博客之星Top200奖品

CSDN App 扫码分享
分享
1
2
打赏
  • 复制链接
  • 举报
下一条:
原以为js取数组里元素最大值就是这样的:function getMaxValue(arr) {let maxValue = arr[0];for (let i = 1; i < arr.length; i++) {if (arr[i] > maxValue) {maxValue = arr[i];}}return maxValue;}// 测试const a = [2, 34, 4, 23, 2];console.log(getMaxValue(a)); // 输出 34但ChatGPT说使用ES6语法可以是这样的:function getMax(arr) {return Math.max(...arr);}const a = [2, 34, 4, 23, 2];console.log(getMax(a)); // 输出 34如果不使用ES6,则可以这样:function getMaxValue(arr) {return Math.max.apply(null, arr);}let a = [2, 34, 4, 23, 2];console.log(getMaxValue(a)); // 输出: 34还是需要多学习。
立即登录