Last active
December 17, 2015 23:49
-
-
Save bingeboy/5692603 to your computer and use it in GitHub Desktop.
Merge Arrays Into Object Literal
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
var x = ["blue", "yellow", "red", "green", "brown", "grey", "gray", "orange"]; | |
var y = ["james", "john", "robert", "michael", "william", "david", "richard", "wayne"]; | |
function merge2array(a, b) { | |
var obj = {}; | |
var l = a.length; | |
var i; | |
for (i = 0; i < l; i++) { | |
obj[a[i]] = b[i]; | |
} | |
return obj; | |
} | |
var obj = merge2array(x, y); | |
console.log(obj); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also remember to wrap the object in {} for rest api.
Example: var wrapper:{"title here": obj}