JavaScript Array Object

Source: Internet
Author: User
Tags javascript array

<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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.