How can I store reference to a variable within an array?

后端 未结 5 1474
小蘑菇
小蘑菇 2020-12-17 20:58

I\'m trying to create an array that maps strings to variables. It seems that the array stores the current value of the variable instead of storing a reference to the variabl

5条回答
  •  借酒劲吻你
    2020-12-17 21:15

    Put an object into the array instead:

    var name = {};
    name.title = "foo";
    
    var array = [];
    
    array["reference"] = name;
    
    name.title = "bar";
    
    // now returns "bar"
    array["reference"].title;
    

提交回复
热议问题