I want to create an array like:
var fruits[ ]=[ [1] ["Grapes","mango","orange"] , [2] ["banana"], [A] ["Avocado","Apple"] , [P] ["Pear","Papaya","pomegranate","plum"] ];
And accordingly I want to access the above array using key value pairing or something like that.
For example, if I have a dropdown with values:
<select>
<option value="1">1</option>
<option value="2">2</option>
<option value="A">A</option>
<option value="P">P</option>
</select>
Depending upon my selection, it should display the respective values using a for loop like if I select option "A" then using the for loop it should display the values corresponding to option A ie. Avocado Apple.
How can I achieve this?
var fruits = {"1" : ["Grapes","mango","orange"], "2" : ["banana"], "A" : ["Avocado","Apple"], "P" : ["Pear","Papaya","pomegranate","plum"]}Then you can loop over the keys and use that key to get the array op options you want to use.