Skip to content

Instantly share code, notes, and snippets.

@epicure
Created October 11, 2011 12:44
Show Gist options
  • Save epicure/1277977 to your computer and use it in GitHub Desktop.
Save epicure/1277977 to your computer and use it in GitHub Desktop.
array2object
var arr = ['a','b','c','d','e'];
var objectify = function() {
var o = {};
arr.reduce( function (prev, cur, i, array) {
(array.length % 2) && array.length - 1 === i ? o[cur] = null : 0;
if(i % 2) {
return o[prev] = cur;
}
else {
return cur;
}
});
return o;
}
var o = objectify(arr);
console.log(o);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment