I have two arrays:
array1 = [\"Bob\", \"John\", \"Dave\"];
array2 = [1, 2, 3];
Is there combine the two into a javascript array filled with obj
It's one of the ways how to achieve it. You can use Array#forEach
function to iterate over every element from array1
. Then, create empty object and set specified properties - in your case: meta
and value
. Then - assign elements to it and just push it into the arr
variable.
var array1 = ["Bob", "John", "Dave"],
array2 = [1, 2, 3],
arr = [];
array1.forEach(function(v,i){
var obj = {};
obj.meta = v;
obj.value = array2[i];
arr.push(obj);
});
console.log(arr);