<DOCTYPEHTML><HTML><Head> <title>Array</title></Head><Body> <Scripttype= "Text/javascript"> //1. No parameter constructor, create an empty array //var a1=new Array (1,2,3,4); //document.write (A1) vara= NewArray (); a[0] = "1 Chaoxiaolong"; a[1] = "2 Chaoxiaolong"; a[2] = 3; for(varI=0; I<A.length;i++){ //document.write (A[i]); //document.write ("<br>"); } //document.write (" //use the for...in declaration to loop through the elements in an array for(heheincha) { //document.write (A[hehe]); //document.write ("<br>"); } //document.write (" //Merging Arrays concat (merging) vararr= NewArray () arr[0] = "Hello"arr[1] = "Word"arr[2] = "name" //document.write (Arr.concat ()); //document.write (" //array Merge string join ("") //document.write (Arr.join ("")); //document.write ("<br>"); //Sort Array Values functionSortnumber (A, b) {returna-B}vararr= NewArray (6) arr[0] = "Ten"arr[1] = "5"arr[2] = " +"arr[3] = " -"arr[4] = " +"arr[5] = "1" //document.write (Arr.sort (sortnumber)) //change the values in an arrayarr[5]="Opel"; //document.write (arr[5]) //Delete the last value in an array vara= NewArray () a[0] = "Hello"a[1] = "Aword"a[2] = "name" //document.write (A.pop ()) //9. When adding a new array to the array; and returns the new length. //document.write (A.push ("James") + "<br/>") //document.write (a) //reverses the order of the elements in the array. //document.write (A.reverse ()) //use Shift () to delete and return the first element of the array. //document.write (A.shift () + "<br/>") //use Slice () to select the first few arrays and output the values //document.write (A.slice (1) + "<br/>") //sorting an array //document.write (A.sort ()) //convert an array to a string //document.write (a.tostring ()) //converts the array to a local array and returns the result. //document.write (a.tolocalestring ()) //add a value to the beginning of a string //a.unshift ("William") //The main difference between ToString () and valueof () is that ToString () returns a string, whereas valueof () returns the original object //document.write (a) </Script></Body></HTML>
JavaScript Array Object