Javascript using variable as array name

后端 未结 5 1120
醉话见心
醉话见心 2020-12-18 15:29

I have several arrays in Javascripts, e.g.

a_array[0] = \"abc\";
b_array[0] = \"bcd\";
c_array[0] = \"cde\";

I have a function which takes the arra

5条回答
  •  一整个雨季
    2020-12-18 16:24

    I believe any variables you create are actually properties of the window object (I'm assuming since you used alert that this is running in a web browser). You can do this:

    alert(window[array_name][0])
    

提交回复
热议问题