array.push is not a function - when working with reduce [duplicate]
The return value of Array#push
is the new length of the array after the push. This means that in the second iteration acc
is a number, which doesn't have the push method.
The fix is simple - separate the push and return statements:
const secondArray = [1, 2, 3].reduce((acc, item) => { acc.push(1); return acc;}, []);console.log(secondArray);