Created
February 22, 2017 10:04
-
-
Save samzeng/60a1bce61fa70bcfd7235be3df70fac6 to your computer and use it in GitHub Desktop.
Combining two arrays form a object
This file contains hidden or 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 keys = ['a', 'b', 'c']; | |
var values = ['1', '2', '3']; | |
var obj = {}; | |
var objArr = []; | |
for (var i = 0; i < keys.length; i ++) { | |
obj[keys[i]] = values[i]; | |
} | |
objArr.push(obj); | |
console.log(obj); // => {a: "1", b: "2", c: "3"} | |
console.log(objArr); // => [{a: "1", b: "2", c: "3"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment