Within my JavaScript code, I am working with an associative (two-dimensional) array (myObj[x][y]
). Each row in this array contains a different number of elements denoted by 'n', where the first value signifies the amount 'n' as shown below:
{"amount"=>"n", "key0"=>"value0","key1"=>"value1"..."keyn"=>"valuen"}
During a loop iteration, I need to access these values using the format:
for (i=o; i=n-1;i++){
current=myObj[row-x].key-y; //code to interact with current
}
I am trying to figure out how to dynamically build the index .key-y
so that I can successfully access the values. Is there a way to achieve this by constructing a string such as
"myObj[row-x].key-"+ i.toString()}"
?
The given JSON data...
"[{\"object_type\":\"villa\",\"object_name\":\"Villa at Maries\",\"object_id\":\"1\",\"mainimg\":\"images\/maries\/IMG1.jpg\",\"object_descreption\":\"BLA BLA BLA.\",\"smallimg0\":\"images\/maries\/img1f.jpg\",\"smallimg1\":\"images\/maries\/img1a.jpg\",\"smallimg2\":\"images\/maries\/img1b.jpg\",\"smallimg3\":\"images\/maries\/img1c.jpg\",\"amencount\":4,\"amenitie0\":\"A\/C\",\"amenitie1\":\"Kitchen\",\"amenitie2\":\"Wi Fi\",\"amenitie3\":\"Parking\"},{\"object_type\":\"villa\",\"object_name\":\"Villa at Agia Marina\",\"object_id\":\"2\",\"mainimg\":\"images\\agiamarina\...
Appreciate all the help provided! I have now found the solution, which was simpler than I thought!