2016-01-29 86 views
0

如何通過最小化語句的數量,簡化爲一個數組以下編碼的數量,簡化爲一個數組以下編碼:如何最大限度地減少報表

var weekdays = new Array(); 
weekdays[0]= "Sun"; 
weekdays[1]= "Mon"; 
weekdays[2]= "Tue"; 
weekdays[3]= "Wed"; 
weekdays[4]= "Thu"; 
weekdays[5]= "Fri"; 
weekdays[6]= "Sat"; 
+0

歡迎StackOverflow上。你想要做什麼?如果你願意,你可以通過'var weekdays = [「Sun」,「Mon」,「Tue」,「Wed」,「Thu」,「Fri」,Sat「]直接初始化數組。 –

回答

1
var weekdays = ["Sun","Mon",Tue","Wed","Thu","Fri","Sat"]; 
0
//You can define an array in one line 
var weekdays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; 
//Then you can loop the array using forEach() function 
weekdays.forEach(function(element) { 
    console.log(element); 
}); 
相關問題