I have an object like this:
var object = {"American":[{"question":"What is the capital?", "answer":"..."}, ... ]};
I have also a variable:
var language = "American";
So, my question is: How can i use the variable called language as a key for the array with all the questions? I have already tried this:
object.language[0].question
and object.[language][0].question
.
Asked
Active
Viewed 21 times
0

Sondre Sørbye
- 529
- 1
- 7
- 15
-
1`object[language][0].question` – CRice Oct 31 '17 at 17:20
-
1Well you do not use bracket notation correctly.... error in console should point that out with the extra `.` – epascarello Oct 31 '17 at 17:20
-
object[language][0].question worked perfectly – Sondre Sørbye Oct 31 '17 at 17:31