Last active
August 29, 2015 14:24
-
-
Save robinweser/49986e2cb3bcc5d7ee88 to your computer and use it in GitHub Desktop.
Transform an Object to an ES6 Map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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