2


I'm trying to create two dimensional array and populate a dropdown using it.
But I'm getting Uncaught SyntaxError: Unexpected string error.

var cuisines = ["001","Australian"],["002","American"];     

var sel = document.getElementById('CuisineList');
for(var i = 0; i < cuisines.length; i++) {
    var opt = document.createElement('option');
    opt.innerHTML = cuisines[i][1];
    opt.value = cuisines[i][0];
    sel.appendChild(opt);
}
<select id="CuisineList"></select>


Please help me. Thanks.

0

3 Answers 3

4

You need outer brackets when defining your two dimensional array.

var cuisines = [["001","Australian"],["002","American"]];

Also, looks like you're using the letter "o" instead of the number 0 for one of your indexes.

Sign up to request clarification or add additional context in comments.

Comments

2

I did not investigate your code deeply but you have error:

 opt.value = cuisines[i][o];

should be

 opt.value = cuisines[i][0];

you are using "o" letter instead of 0 (zero)

Comments

2

Change var cuisines = ["001","Australian"],["002","American"]; to var cuisines =[ ["001","Australian"],["002","American"]]; so you actually have a two dimensional array, and change your [o] to [0].

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.