在 Javascript 中,知道我可以设置一个数组,以便键是一个自动编号(从 0 开始)分配的数组:
var d_names = new Array("Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday");
// Key for Sunday is '0'
如果我想分配密钥,我可以这样做:
var d_names={};
d_names[5]="Sunday";
d_names[6]="Monday";
d_names[7]="Tuesday";
d_names[8]="Wednesday";
d_names[9]="Thursday";
d_names[10]="Friday";
d_names[11]="Saturday";
// Key for Sunday is '5'
但是有没有像 PHP 那样分配键的速记方法?
var d_names = new Array(5=>"Sunday", 6=>"Monday", 7=>"Tuesday", 8=>"Wednesday",
9=>"Thursday", 10=>"Friday", 11=>"Saturday");
// Doesn't work