StackOverflow - StackOverflow
Reduce with deconstruction or forEach - Iteration and Airbnb JavaScript Style Guide
Answered on the github issue (which should be the first and only place you go for questions on this guide):
Since that's invalid syntax, I assume your object is:
things = {
table: 'red',
chair: 'green'
}
Your first example, with the reduce
, is correct. "Seems expensive" is something that you shouldn't worry about - performance is the least important thing, only to be concerned about after code is correct, clean, tested, and profiled.
Only if it ends up being necessary (as determined by fully benchmarking your app, not by microbenchmarks like jsperf), then you'd use your forEach approach next, and then if it still was necessary, you'd devolve it to a for
loop.
Was this helpful?
Related Articles
Have a different question?
Can't find the answer you're looking for? Submit your own question to our community.
🛎️ Get Weekly OTA Fixes
New answers, vendor issues, and updates — straight to your inbox.