variable as index in an associative array - Javascript

前端 未结 7 1268
时光说笑
时光说笑 2021-02-03 23:39

I\'m trying to create an associative array, create an empty array, and then add a (indexName -> value) pair:

var arrayName = new Array;

arrayName[\         


        
7条回答
  •  抹茶落季
    2021-02-03 23:58

    use arrayName[var1+var2]

    Note that arrayName.var is the same as arrayName["var"] -- it's just syntactic sugar. The second form is mostly used when dealing with the kind of problems that you are facing - dynamic object keys, and keys that are not alphanumeric (think of arrayName[".eval()"]; this is a perfectly legal object key that has nothing to do with the javascript eval() function)

提交回复
热议问题