JS数组的使用


<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script type="text/javascript"> //定义数组的三种方式 var arr1 = [1,2,3,4,'hello']; document.write(arr1+"<br/>"); var arr2 = []; document.write(arr2+"<br/>"); var arr3 = new Array(1,2,3); document.write(arr3+"<br/>"); var arr4 = new Array(); document.write(arr4+"<br/>"); //使用数组 //下标从0开始 arr1[0] = "apple"; document.write(arr1[0]+"<br/>"); //可以添加新的元素,可以跳着添加 arr1[6] = 123; document.write(arr1+"<br/>"); document.write(arr1[7]+"<br/>");//undefined document.write(arr1.length+"<br/>"); </script> </head> <body> </body> </html>

  

 

posted @ 2017-02-16 17:26  john。  阅读(147)  评论(0编辑  收藏  举报