4 ms·
Object.fromEntries will be super useful, surprised it’s taken this long to become a native feature.
by jeffwass 7y ago
Object.fromEntries will be super useful, surprised it’s taken this long to become a native feature.
- vmasto 7y agoWhat would some common/helpful use cases be?
- tazard 7y agoI often use Object.entries so that I can use Array.filter/map/foreach on an object, but then I need to use Array.reduce to hack it back into an object. Object.fromEntries solves this.
- baron816 7y agoYeah this is what I’m most excited for. filter and map and my preferred array traversal methods. reduce can be awkward though, and people abuse it by using it to replace or combine filter and map. fromEntries almost makes reduce unnecessary when working with objects.
- masklinn 7y agoFunctional transformation of objects. There are lots of HOFs working on arrays / iterators but none working on object. fromEntries allows easily converting from object to entries, manipulating the entries sequence and converting back to an object. The last step is pretty annoying without it. The entire thing is very common in Python, where Object.entries() is spelled `.items()` and `Object.fromEntries(…)` is spelled `dict(…)`
- STRML 7y agoIt's a lot more verbose than _.mapValues() is, but it's nice to have a relatively simple solution without using a library.
- deleted 7y ago[deleted]
- Scarbutt 7y agoReally though, don't know why this isn't the most mentioned feature in this thread, processing objects in JS has always been annoying.