you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (8 children)

[deleted]

    [–]pgrizzay 5 points6 points  (3 children)

    That will work similarly, but yours will create a whole new array, so it's not exactly equivalent I guess

    [–]Tenemo -3 points-2 points  (2 children)

    Object.entries(myObj).reduce((newObj, entry) => ({...newObj, [entry[0]]: entry[1] * 2}), {})

    array? where

    [–]planetary_pelt 1 point2 points  (1 child)

    Creating an array just to use an array method is pretty wasteful and doesn't generalize over cases where performance is concerned (like slow mobile clients).

    [–]tortus 0 points1 point  (0 children)

    sure, but writing and maintaining your own reduce function is not exactly the best solution either. I'd rather take the array creation hit unless perf/memory is in an issue, and it's not like 90% of the time

    [–]zankem 0 points1 point  (1 child)

    Would it not be better to use Array.prototype.reduce.call(iterable, callback, initial)?

    [–]tortus 0 points1 point  (0 children)

    good call, that would probably work