3 ms·
What would some common/helpful use cases be?
by vmasto 7y ago
What 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]