You could take a combination of
-
Object.assign
for building a new object of single objects as parts, -
spread syntax
...
for taking an array as parameters, -
Object.entries
for getting an array with key/value arrays, -
Array#map
for doing the work with key and values, -
destructuring assignment for separating an array in key and value variables,
-
computed property names for getting a new object with a given key.
var object = { a: 1, b: 2 },
result = Object.assign(...Object.entries(object).map(([k, v]) => ({ [k]: v * 2 })));
console.log(result);
3
solved Is there a JavaScript proposal for an operator to apply a function to every item in a collection?