Passionate about building great technology and connecting with people to create positive change. Happy to answer questions about transitioning to tech. Find me on Twitter @lounecl
Full-time web dev; JS lover since 2002; CSS fanatic. #CSSIsAwesome
I try to stay up with new web platform features. Web feature you don't understand? Tell me! I'll write an article!
He/him
I definitely have mixed feelings about this paradigm. I absolutely see the value in quickly mapping from one object to another, but I agree that Object.fromEntries(Object.entries(obj).map(...)) is not the most readable thing.
On the one hand, I sort of expect that it will become a paradigm that is so ubiquitous that everyone will just get used to seeing it and immediately recognize what it's doing, so readability will become less of a problem over time. But on the other hand, if it is going to become that common of an operation, I sort of wish there was a built-in method for it, something like Object.mapEntries(([key, val]) => [key, val+1]), that just did it all in one go.
All that said, it does become a little more readable when split onto a few lines:
I’ve started using .map with Object.fromEntries in places I would have used reduce but it does make it look even more cryptic.
Haha it does only because of the chaining to keep everything on one line. I think if you split it up as Ken does, it's a ton more effective
I definitely have mixed feelings about this paradigm. I absolutely see the value in quickly mapping from one object to another, but I agree that
Object.fromEntries(Object.entries(obj).map(...))
is not the most readable thing.On the one hand, I sort of expect that it will become a paradigm that is so ubiquitous that everyone will just get used to seeing it and immediately recognize what it's doing, so readability will become less of a problem over time. But on the other hand, if it is going to become that common of an operation, I sort of wish there was a built-in method for it, something like
Object.mapEntries(([key, val]) => [key, val+1])
, that just did it all in one go.All that said, it does become a little more readable when split onto a few lines:
We need Object.mapEntries then I think!