Javascript 数学最小值和最大值返回NaN

Javascript 数学最小值和最大值返回NaN,javascript,math,Javascript,Math,我想从一组在运行时不断变化的数字中记录最小值和最大值。 我正在使用ES5Math.min和Math.max。我甚至克隆了输入数组以避免并发更改。这是我的代码: var runTimes = input.runTimes.slice(0); // clone input to avoid further changes console.log("RUN TIMES", runTimes); var min = Math.min(runTimes); var max = Math

我想从一组在运行时不断变化的数字中记录最小值和最大值。 我正在使用ES5
Math.min
Math.max
。我甚至克隆了输入数组以避免并发更改。这是我的代码:

var runTimes = input.runTimes.slice(0); // clone input to avoid further changes
console.log("RUN TIMES", runTimes);
var min = Math.min(runTimes);
var max = Math.max(runTimes);
console.log("RUN TIMES MIN", min);
console.log("RUN TIMES MAX", max);
我得到了
NaN
,即使所有项目都是数字,通过日志验证:
Math.min
Math.max
不需要数组,但需要不同的数字。 请试试这个:

var min = Math.min(...runTimes);
var max = Math.max(...runTimes);
阅读文档中关于其用法的演示