1

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!

1 Answer 1

3

The reduce function expects either a non-empty array or an initial value as parameter.

Try this

Array.prototype.reduce.call(fields, function (prev, curr) ..... }, null);
Sign up to request clarification or add additional context in comments.

1 Comment

Array.prototype.reduce expects 3 parameters, you just have 2, so no initial value is given.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.