如下所示:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>javascript定义数组的三种方法</title> </head> <body> <> <script> var cars=new Array(); cars[0]="奥迪"; cars[1]="宝马"; cars[2]="兰博基尼"; document.write("JavaScript定义数组的第一种方式:new Array(),然后依次赋值a[0]="); document.write("<br />"+cars[0]); document.write("<br />"+cars[1]); document.write("<br />"+cars[2]); </script> <> <script> var i; var cars=new Array("奥迪","宝马","兰博基尼"); document.write("<br />"+"JavaScript定义数组的第二种方式new Array('xx','yy')"); for(i=0;i<cars.length;i++) { document.write("<br />"+cars[i]); } </script> <> <script> var i; var cars=["奥迪","宝马","兰博基尼"]; document.write("<br />"+"JavaScript定义数组的第三种方式=['xx','yy','zz']"); for(i=0;i<cars.length;i++) { document.write("<br />"+cars[i]); } </script> </body> </html>
以上就是小编为大家带来的JavaScript定义数组的三种方法(new Array(),new Array('x','y')全部内容了,希望大家多多支持查字典教程网~