+ 3

[Solved] Can I get a variables value to use it to bring an array's value.

I want to use my variable to bring an array's output. Like bellow: var arr = ["A", "B", "C"] var input = prompt("input"); var output = arr[(instead writing the number of element to get directly, I want here the users input) input] Please answer my question.

28th Oct 2020, 8:35 PM
Adil
Adil - avatar
2 Antworten
+ 3
the input by user is stored in a variable called input. so u would use arr [ input ] if input is 0 it would mean: arr [ 0 ] which is equal to "A"
28th Oct 2020, 9:05 PM
maf
maf - avatar
+ 3
Thanks a lot! My code is working correctly now.
28th Oct 2020, 9:39 PM
Adil
Adil - avatar