Skip to content

Instantly share code, notes, and snippets.

@elycruz
Created December 15, 2013 23:51
Show Gist options
  • Save elycruz/7980005 to your computer and use it in GitHub Desktop.
Save elycruz/7980005 to your computer and use it in GitHub Desktop.
Gist for generating a map from an array of arrays [['a': 'hello'], ['b': 'world']].
function fromArrayMap (arrayMap, convertAllArrays) {
convertAllArrays = convertAllArrays || true;
var map = new Map(), value;
arrayMap.forEach(function(x) {
value = Array.isArray(x[1]) ? fromArrayMap(x[1]) : x[1];
map.set(x[0], value);
});
return map;
}
Map.prototype.fromArrayMap = fromArrayMap;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment