javascript and dom1

时间:2020-12-03 01:12:04
<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);//
var beatles=["John","Paul","George","Ringo","Liuwei"];
console.log(beatles[4]);//Liuwei
var lennon=["John",1940,1943];
console.log(lennon.length);//
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>