Skip to content

Instantly share code, notes, and snippets.

@ryasmi
Last active December 16, 2015 11:09
Show Gist options
  • Save ryasmi/5425766 to your computer and use it in GitHub Desktop.
Save ryasmi/5425766 to your computer and use it in GitHub Desktop.
Converts an array values to an object using an arrays on keys. Source: http://stackoverflow.com/questions/12199051/merge-two-arrays-of-keys-and-values-to-an-object-using-underscore
// Using func. https://gist.github.com/ryansmith94/5564105
func("toObject", function (keys, values) {
var i;
var len = keys.length;
var result = {};
values = values || this;
for (i = 0; i < len; i += 1) {
result[keys[i]] = values[i];
}
return result;
}, Array.prototype);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment