JavaScript “associative” array access

前端 未结 3 1285
一生所求
一生所求 2021-01-02 01:21

I have a simple simulated array with two elements:

bowl["fruit"] = "apple";
bowl["nuts"] = "brazilian";
3条回答
  •  悲&欢浪女
    2021-01-02 01:35

    You could use JSON if you don’t want to escape the key:

    var bowl = {
      fruit: "apple",
      nuts: "brazil"
    };
    
    alert(bowl.fruit);
    

提交回复
热议问题