Why can I add named properties to an array as if it were an object?

前端 未结 7 2195
盖世英雄少女心
盖世英雄少女心 2020-11-22 06:33

The following two different code snippets seem equivalent to me:

var myArray = Array();
myArray[\'A\'] = \"Athens\";
myArray[\'B\'] = \"Berlin\";
         


        
7条回答
  •  广开言路
    2020-11-22 07:06

    The {}-notation is just syntactical sugar to make the code nicer ;-)

    JavaScript has many similar constructs like the construction of functions, where function() is just a synonym for

    var Func = new Function("", "");
    

提交回复
热议问题