Convert a string to a variable name in javascript?

后端 未结 3 1406
清歌不尽
清歌不尽 2021-01-19 21:43

Ok you have a set of variables:

var height1 = 10
var height2 = 20
...
var height7 = 70;

The user has given input and you need to get the v

3条回答
  •  悲&欢浪女
    2021-01-19 22:30

    Do you have control over the variables as an array of heights would suit you much better, failing that, create the array yourself so you take height 1..X push them onto an array and then you can just use the index.

提交回复
热议问题