1234567891011121314151617181920212223242526272829303132333435 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <script>
- var arr = [];
- // 数组通过下标去添加内容
- // 下标(index)从0开始
- // 数组的最大下标就是length-1
- // 数组长度 length
- arr[0] = 12;
- arr[1] = 23;
- console.log(arr);
- console.log(arr.length);
- // 数组可由多数据类型组成
- var arr1 = [1,2,'eee',true,undefined,null];
- console.log(arr1);
- // 读取数组中的值 arr[index]
- console.log(arr1[3])
- var arr2 = new Array('12','22',false);
- arr2[3] = true;
- console.log(arr2);
- // 遍历数组
- for(var i=0;i < arr1.length;i++) {
- // document.write(arr1[i])
- console.log(arr1[i]);
- }
- console.log(typeof arr1);
- </script>
- </body>
- </html>
|