I have a Java script array as below: - the first element is a string - the second element is a array -- the first element of this is a string -- the second element is an array --- the first element of this is a string --- the second element is an array : : Practically, this goes on to a level of 5.
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]]
]]
]
];
I know the path to a selected photograph (and the index values are stored in an array "path") Example [1][0][1][2] is Year 2000 -> Rome -> p3.jpg
Knowing these index values, how can I access p3? In the code, I formed a string variable: var index="[1][0][1][2]". Now I need to do something like: photoList+index I tried eval(photoList + index), which does not work. I also tried using a loop, with slice:
var elem = photoList;
for (var i=0; i<path.length; i++) {
elem = elem.slice(path[i], path[i+1];
}
Any ideas would be appreciated.