<script type="text/javascript"> //数组 var beatles=Array(4); var beatles=Array(); console.log(beatles);//[] beatles[0]="John"; beatles[1]="Paul"; beatles[2]="George"; beatles[3]="Ringo"; console.log(beatles[3]);//Ringo var beatles=Array("John","Paul","George","Ringo"); console.log(beatles.length);//4 var beatles=["John","Paul","George","Ringo","Liuwei"]; console.log(beatles[4]);//Liuwei var lennon=["John",1940,1943]; console.log(lennon.length);//3 var name="John"; beatles[0]=name; console.log(beatles[0]);//John var names=["Ringo","John","George","Paul"]; beatles[1]=names[2]; console.log(beatles[1]);//George var lennon=["Ringo",1940,false]; var beatles=[]; beatles[0]=lennon; console.log(beatles[0]);//["Ringo",1940,false] var lennon=Array(); lennon["name"]="John";//不建议用这种关联数组 lennon["year"]=1943; lennon["living"]=false; console.log(lennon);//[] //living false //name "John" //year 1943 </script>
原文:http://www.cnblogs.com/xl900912/p/4211911.html