** There are several ways to create arrays:

Methods a

This is the simplest method, while relatively troublesome, suitable for beginners.

The code is as follows:

var arr1=new Array()
arr1[0] ="a"
arr1[1] ="b"
arr1[2] ="c"
arr1[3] ="d"
document.write("arr1:"+arr1+"<br />");

Copy the code

Method 2

The code is as follows:


var arr2=new Array(3); 
arr2[0] =1;
arr2[1] =2;
arr2[2] =3;
document.write("arr2:"+arr2+"<br />")
Copy the code

Note: The 3 in Array(3) refers to the length of the Array, not the upper limit of the Array.

Methods three

The code is as follows:

 var arr3=new Array([3]); 
        arr3[0] =3;
        document.write("arr3:"+arr3+"<br />")
        document.write("Length of arr3:"+arr3.length+"<br />")

Copy the code

Note: Array([3]) here refers to an Array of length 1, with the first number 3.

Methods four

The code is as follows:

var arr4=["12"."lf"."Top 10 Technologies"."sui"]
        document.write("arr4:"+arr4+"<br />")
        document.write(arr4[2] +"<br />");  // Prints the specified subscript element

Copy the code

This method is the most convenient of these methods and the most recommended

Array traversal

var arr=["12"."lf"."Top 10 Technologies"."sui"]
  for(var i=0; i<arr4.length; i++){
            document.write("arr["+i+"]"+":"+arr[i]+"<br />")}Copy the code

The For… In statement

var arr=["12"."lf"."Top 10 Technologies"."sui"]
  document.write("Use for... In statement to iterate over group arr:"+"<br />")
        var pro="";
        for(pro in arr){
            document.write("arr["+i+"]:"+arr[pro]+"<br />")}Copy the code