From imperative to functional JavaScript
Diogo Spínola
8169

const result = ['zero', 'one', 'two']
.reduce((accumulated, current, index) => {
return Object.assign({}, accumulated, {
[current]: index
})
})
console.log(result) // {zero: 0, one: 1, two: 2}

Maybe you lost the initial value “{}” , so the console you showed is not correct .Right?