确认变量是否是数组

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h1>JavaScript Array.isArray()</h1>
  6.  
  7. <p>单击按钮以检查“fruits”是否为数组。</p>
  8.  
  9. <button onclick="myFunction()">试一试</button>
  10.  
  11. <p id="demo"></p>
  12.  
  13. <script>
  14. function myFunction() {
  15. var fruits = ["Banana", "Orange", "Apple", "Mango"];
  16. var x = document.getElementById("demo");
  17. x.innerHTML = Array.isArray(fruits);
  18. }
  19. </script>
  20.  
  21. </body>
  22. </html>