14.数组.html 987 B

1234567891011121314151617181920212223242526272829303132333435
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. var arr = [];
  11. // 数组通过下标去添加内容
  12. // 下标(index)从0开始
  13. // 数组的最大下标就是length-1
  14. // 数组长度 length
  15. arr[0] = 12;
  16. arr[1] = 23;
  17. console.log(arr);
  18. console.log(arr.length);
  19. // 数组可由多数据类型组成
  20. var arr1 = [1,2,'eee',true,undefined,null];
  21. console.log(arr1);
  22. // 读取数组中的值 arr[index]
  23. console.log(arr1[3])
  24. var arr2 = new Array('12','22',false);
  25. arr2[3] = true;
  26. console.log(arr2);
  27. // 遍历数组
  28. for(var i=0;i < arr1.length;i++) {
  29. // document.write(arr1[i])
  30. console.log(arr1[i]);
  31. }
  32. console.log(typeof arr1);
  33. </script>
  34. </body>
  35. </html>