把数组转换为字符串 - toString()

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h1>JavaScript 数组方法</h1>
  6.  
  7. <h2>toString()</h2>
  8.  
  9. <p>toString() 方法以逗号分隔的字符串返回数组:</p>
  10.  
  11. <p id="demo"></p>
  12.  
  13. <script>
  14. var fruits = ["Banana", "Orange", "Apple", "Mango"];
  15. document.getElementById("demo").innerHTML = fruits.toString();
  16. </script>
  17.  
  18. </body>
  19. </html>