Skip to content

Instantly share code, notes, and snippets.

@robinweser
Last active August 29, 2015 14:24
Show Gist options
  • Save robinweser/49986e2cb3bcc5d7ee88 to your computer and use it in GitHub Desktop.
Save robinweser/49986e2cb3bcc5d7ee88 to your computer and use it in GitHub Desktop.
Transform an Object to an ES6 Map
function objectToMap(obj){
let map = new Map();
let i;
let keys = Object.keys(obj);
let length = keys.length;
for (i = 0; i < length; ++i){
let temp = obj[keys[i]];
if (temp instanceof Object){
map.set(keys[i], objectToMap(temp));
} else {
map.set(keys[i], temp);
}
}
return map;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment