In my Java script array, the structure goes up to 5 levels deep with elements containing strings and arrays.
photoList =
[Photographs, [
[2000, [
[London, [pic1.jpg, pic2.jpg, pic3.jpg]],
[Rome, [p1.jpg, p2.jpg, p3.jpg....]]
]],
[2001, [
[Berlin, [x1.jpg, x2.jpg,....]],
[Munich, [y1.jpg, y2.jpg, y3.jpg,...]],
[Frankfurt, [z1.jpg, z2.jpg]]
]]
]
];
Given an array "path" with index values that points to a specific photograph, for example, [1][0][1][2] corresponds to Year 2000 -> Rome -> p3.jpg. How can I access p3 using these index values?
I tried creating a string variable index="[1][0][1][2]" and attempted to access the element using photoList+index
, but it didn't work. I also experimented with using a loop and slice method:
var elem = photoList;
for (var i=0; i<path.length; i++) {
elem = elem.slice(path[i], path[i+1]);
}
If you have any insights or ideas on how to solve this problem, please share them. Your input is appreciated.