Array reduce in javascript

broken image
broken image

Once the loop as finished, I’ve assigned prev to reduced to act like Reduce’s final return value. We then re-assign prev each time and add + our next.price to it. From there, we’ll loop our items and create a next variable.

broken image

reduce (( prev, next, index, array ) => reduced = prev įirst we declare reduced and prev to assign an initialValue of 0 just like Reduce.

broken image