1 <!DOCTYPE html> 2 <html> 3 <head lang="en"> 4 <meta charset="UTF-8"> 5 <title></title> 6 </head> 7 <body> 8 <script> 9 10 11 var arr = ["刘备","关羽","张飞"]; 12 13 //数组长度 14 // console.log(arr); 15 // console.log(arr.length); 16 17 //通过索引值获取元素。 18 console.log(arr[0]); 19 console.log(arr[1]); 20 console.log(arr[2]); 21 console.log(arr[1222]); 22 23 //通过索引值,给元素赋值 24 arr[0] = "韩信"; 25 arr[1] = "萧何"; 26 arr[2] = "张良"; 27 28 console.log(arr[0]); 29 console.log(arr[1]); 30 console.log(arr[2]); 31 </script> 32 </body> 33 </html>