Skip to content

Instantly share code, notes, and snippets.

@samzeng
Created February 22, 2017 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samzeng/60a1bce61fa70bcfd7235be3df70fac6 to your computer and use it in GitHub Desktop.
Save samzeng/60a1bce61fa70bcfd7235be3df70fac6 to your computer and use it in GitHub Desktop.
Combining two arrays form a object
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