0

I have a callback that I am using like

return innerArray.reduce((prev, curr, i, array) => {

However, when I try to use the array (for me this is an array of objects) like

array[i-1].outerIndex

I get a JavaScript error that I cannot read a property of undefined, reading outerIndex. The only way I was able to get this to work is with

let prevObj = { ...array[i - 1] };
prevObj.outerIndex

Is there something that is not an array in the argument passed to the reduce callback?

1 Answer 1

1

Is there something that is not an array in the argument passed to the reduce callback?

No. It is an array.

The error message says that array[i-1] is undefined.

This is probably when it is dealing with the first item in the array so i is 0 so you are trying to access array[-1] which is out of bounds.

Sign up to request clarification or add additional context in comments.

Comments

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.