I am trying to generate an HTML select menu using a javascript array. The array keys should be used as values of options. And if the array keys are entered as numbers(as what I have done in my code) they should be accepted.
a([selected="No of rooms", 1="1", 2="2", 3="3", 4="4", 5="5"]);
function a(x) {
elementString = "<select>";
for(var i in x) {
elementString += '<option value="">'+i+'</option>';
}
elementString += "</select>";
alert(elementString);
}
But this code does not work. And I could not find a way to use array keys as the values of options. Another question I got is, if I put numbers as keys it does not work(This is a requirement).
Edit: jsfiddle link works now