I have been trying to do the following:
var arr1 = ["A", "B"];
var arr2 = ["A", "B"];
// Where the result should be
var arrayOfObjects = [
{
arr1: "A",
arr2: "A"
},
{
arr1: "B",
arr2: "B"
}
];
Essentially I would like to sort out the arrays into objects. I don't know how else to explain in words. I could do this the long and hard way through looping. I am used to this kind of programming because I come from a long history of C and C++ programming. I would like some help figuring this out in a cleaner JS way.
Also if anyone can point me to a great reference for being able to solve problems like this in JS. I have tried looking at W3schools and the MDN but not enough examples are shown when looking up useful functions. Or maybe I just suck at reading the docs and would like references that help me to understand the docs.
A more specific example was asked:
var name = ["John", "Adam"];
var age = ["19","31"];
result = {
{
name: "John",
age: "19"
},
{
name: "Adam",
age: "31"
},
}
Also all arrays are the same length.