My project requires that I have several arrays defined in javascript such as:
var d1 = new Array(2,17,18,19,20);
var d2 = new Array(2,18,19,20);
var d3 = new Array(2,18,21,19,20);
var d4 = new Array(2);
var d5 = new Array(2,18,19,20);
var d6 = new Array(2,18,21,19,20);
etc
I have a <select>
element which contains options with integer values (1,2,3,4...). When the value of said <select>
is changed I need to be able to dynamically switch to the corresponding array.
What is the best way of achieving this?
Edit:
I forgot about the eval
function, so I added something like this to test it:
alert(eval('d'+value)[0]);
However, the problem now is that arrays like d4, with only one value in them are showing up as undefined
.