If they are all in the same order, you can do this:
var firstname = ["john", "peter", "rick"];
var age = [20, 45, 30];
var country = ["Brazil", "USA", "Italy"];
var array = [];
for (var i = 0; i < firstname.length; i++) {
array.push({firstname: firstname[i], age: age[i], country: country[i]});
}
console.log( JSON.stringify(array) );
Note that I changed name
into firstname
: for some reason, it didn’t work with name
, possibly because it is a reserved term in Javascript or the browser.
0
solved convert arrays to a single array of objects