Why using object spread with reduce probably a bad idea
Hey there!
If you have been using JavaScript for a while, you must be familiar with the .reduce()
method of JavaScript arrays.
You might have used it to convert an array of objects to an object, with the spread operator like this -
arr.reduce(
(acc, item) => ({
...acc,
[item.id]: [item.name],
}),
{}
);
While this method may look pretty cool and short, but did you know this technique can take a heavy toll on performance in your JavaScript apps and libraries?
Well, today, I've got a new post for you just for covering why this technique performs poorly and what are some better ways to do it.
Give it a read here! - Why using object spread with reduce probably a bad idea
Cheers,
Prateek
Don't miss what's next. Subscribe to Prateek's Blog: