2016-09-14 53 views
-2

所以我想做一段以一組變量開始的代碼,然後使用.sort()和.length()命令然後按字母順序排序,然後輸出數字結果,有什麼想法?我想出了這個,但迄今爲止只輸出一個數組,其中包含一個函數

`

<h1>task 2</h1> 

<script> 
var products ["Router","Tablet","Printer","Nachos","sandwhich"]; 
document.write(products.sort()); 
document.write(prod caucts.length); 
</script> 

`

回答

0

嘗試下輸出的內容:

<script> 
var products=["Router","Tablet","Printer","Nachos","sandwhich"]; 
products.sort(); 
var enumerated_products=[]; 
products.forEach(function(x,i,arr){enumerated_products.push({x,i})}); 
console.log(enumerated_products); 
</script> 
相關問題