I got this code from a book and I don't understand how this statement "mm=months[mm]" convert to month name string:
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();
My question is this what exactly does the mm=months[mm]
and dy=days[dy]
(convert to month or day name string) do. I don't understand how this statement "mm=months[mm]" convert to month name string, when months is an array. Is this just some build in function of an array?
days[0]
-> "sun", e.g.from the book
I think online free tutorials are very good. But it's just my thought.