這樣做:就是給init VAR一個月以前聲明數組中的元素只有一個非常廉價的方式...(東西會節省你寫一行多個但恕我直言降低代碼的可讀性... ) 所以斷裂下來:
var month = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"] [mydate.getMonth()];
相同
var monthOptionsArray = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
var monthIndex = mydate.getMonth();
var monthActual = monthOptionsArray[monthIndex];
實施例:
var mydate = new Date();
console.log(mydate.getMonth());
var month = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"]; monthI = month[1];
console.log(monthI);
var str = month + ' ' + mydate.getFullYear();
你與節約幾行初始化的VAR月直接... –
考慮接受一個答案,如果它是有幫助 – Geeky