loading...

Discussion on: Basic Javascript: Removing Duplicates from an Array

Collapse
jrdleto profile image
jrdleto

Can't figure out, what does [], in itterable condition

Collapse
jamesthomson profile image
James Thomson

The reduce function uses and accumulator as part of its logic. The [] is the starting value (an empty array) of the accumulator.

Simplified, using the reduce function to produce a total based on an array of values, we could start the reduce loop with the value 0.

const arr = [1,2,3,4,5,6,7,8];

const newArr = arr.reduce((acc, cur) => acc + cur, 0) // 36

We could also start it with another value, perhaps as a running total.

More on reduce: developer.mozilla.org/en-US/docs/W...