DEV Community

Discussion on: Transforming data with Array.reduce

lukaszahradnik profile image
Lukáš Zahradník • Edited on


I would recommend using approach bellow instead of yours (with object destructuring)

const toObject = data.reduce((acc, item) => {
   acc[] = item
   return acc
}, {})
Enter fullscreen mode Exit fullscreen mode

Your approach creates a new object on every iteration which is just more time consuming in the end.

The same applies for the array - use push instead of destructuring.