1var myObject = { 'a': 1, 'b': 2, 'c': 3 };
2
3Object.keys(myObject).map(function(key, index) {
4 myObject[key] *= 2;
5});
6
7console.log(myObject);
8// => { 'a': 2, 'b': 4, 'c': 6 }
1const map = new Map(Object.entries({foo: 'bar'}));
2
3map.get('foo'); // 'bar'
4
1let map = new Map();
2map.set("a", 1);
3map.set("b", 2);
4map.set("c", 3);
5
6let obj = Array.from(map).reduce((obj, [key, value]) => (
7 Object.assign(obj, { [key]: value }) // Be careful! Maps can have non-String keys; object literals can't.
8), {});
9
10console.log(obj); // => { a: 1, b: 2, c: 3 }
1var myObject = { 'a': 1, 'b': 2, 'c': 3 };
2
3for (var key in myObject) {
4 if (myObject.hasOwnProperty(key)) {
5 myObject[key] *= 2;
6 }
7}
8
9console.log(myObject);
10// { 'a': 2, 'b': 4, 'c': 6 }
1import { map } from "ramda"
2
3const double = x => x * 2;
4
5const mappedObject = map(double, {x: 1, y: 2, z: 3}); //=> {x: 2, y: 4, z: 6}