Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

map to object

let map = new Map();
map.set("a", 1);
map.set("b", 2);
map.set("c", 3);

let obj = Array.from(map).reduce((obj, [key, value]) => (
  Object.assign(obj, { [key]: value }) // Be careful! Maps can have non-String keys; object literals can't.
), {});

console.log(obj); // => { a: 1, b: 2, c: 3 }
Source by gist.github.com #
 
PREVIOUS NEXT
Tagged: #map #object
ADD COMMENT
Topic
Name
8+3 =