Here's a mind-bending scenario for you.
Imagine I have two arrays - one containing categories and the other containing arrays that follow the structure of those categories. For example:
var categoryArray = ["Name", "Title", "Hire Date"];
var infoArray = [["John","Project Manager","January 5"], ["Alex","Accountant","December 15"], ["Joanne","Graphic Designer","August 26"]];
I want to combine this data into a single object. To start off, I create an empty object like so:
var myDict = {};
I attempted to achieve this using nested for-loops, trying to populate myDict with the array contents. Here's what I tried:
// Loop through each entry in the infoArray
for (i = 0; i < infoArray.length; i++) {
var row = String("row"+i);
myDict.row = {};
// Loop through each category
for (x = 0; x < categoryArray.length; x++) {
myDict.row.categoryArray[x] = infoArray[i][x];
}
}
Clearly, there are many mistakes here, and I'm stuck on how to fix them. The main issue seems to be using variables/arrays as names for objects. Any help from the all-knowing internet would be greatly appreciated!