简体   繁体   English

Javascript错误“减少没有初始值的空数组”

[英]Javascript error “Reduce of empty array with no initial value”

I got an error like 我有一个错误

Reduce of empty array with no initial value 减少没有初始值的空数组

when do following: 何时执行以下操作:

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

Can someone point me in the right direction? 有人可以指出我正确的方向吗?

Thanks! 谢谢!

The reduce function expects either a non-empty array or an initial value as parameter. reduce函数需要一个非空数组或一个初始值作为参数。

Try this 尝试这个

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM