我从一本书中得到了这段代码,但我不明白这个语句“mm=months[mm]”如何转换为月份名称字符串:
function init(){
var panel = document.getElementById("panel");
var days=["sun","mon","tue","wed","thur","fri","sat"];
var months=["jan","feb","mar","apr","may","jun",
"jul","aug","sep","oct","nov","dec"];
var now = new Date();
var yy = now.getFullYear();
var mm = now.getMonth();
var dd = now.getDate();
var dy = now.getDay();
mm=months[mm]; //convert to month name string
dy=days[dy]; //convert to month name string
var str = dy+","+mm","+dd+","+yy;
panel.innerHTML+="us date string: "+str;
str = dy+","+dd+" "+mm+","+yy;
panel.innerHTML+="<br>uk date string: "+str;
}
window.onload=init();
mm=months[mm]
我的问题是和dy=days[dy]
(转换为月份或日期名称字符串)究竟是做什么的。当月份是一个数组时,我不明白这个语句“mm=months[mm]”如何转换为月份名称字符串。这只是数组的一些内置功能吗?