gpt4 book ai didi

JavaScript 错误 "Reduce of empty array with no initial value"

转载 作者:行者123 更新时间:2023-11-30 09:39:23 24 4
gpt4 key购买 nike

我遇到了类似这样的错误

Reduce of empty array with no initial value

什么时候做以下事情:

var fields = $(".invoiceli");
$(document).delegate(fields, 'change', function() {
Array.prototype.reduce.call(fields, function(prev, curr)
//.....
});
})

有人能指出我正确的方向吗?

谢谢!

最佳答案

reduce 函数需要一个非空数组或一个初始值作为参数。

试试这个

Array.prototype.reduce.call(fields, function (prev, curr) ..... }, null);

关于JavaScript 错误 "Reduce of empty array with no initial value",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41930861/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com