确认变量是否是数组
- <!DOCTYPE html>
- <html>
- <body>
- <h1>JavaScript Array.isArray()</h1>
- <p>单击按钮以检查“fruits”是否为数组。</p>
- <button onclick="myFunction()">试一试</button>
- <p id="demo"></p>
- <script>
- function myFunction() {
- var fruits = ["Banana", "Orange", "Apple", "Mango"];
- var x = document.getElementById("demo");
- x.innerHTML = Array.isArray(fruits);
- }
- </script>
- </body>
- </html>