This article mainly introduces the array object in JavaScript, which can be referenced by friends in the following
First, the definition of the array and the initialization method: var myarray = new Array (1,3.1415, "Love"); Notice here that the elements in the myarray array are not only elements of the same data type, they can be shaped, have floating-point types, have strings, and so on. This shows that JavaScript as a language for the weakening of data types, language more casual, simple. Use Var when defining an object on a row. In this introduction of the limited, at the same time there are some I did not give results, I hope that everyone to experience themselves, try to see what the results are, so as to help the memory. The following bands [] are parameters that can be omitted. Array Property: Length: The length of the array object, that is, the number of elements in the array. Here also note that the subscript of the first element is 0. document.write (myarray.length); The result is the 3 array method: code as follows: Join (< separator >): Concatenate each element in the array, and place the delimiter between elements and elements document.write ( Myarray.join ("-")); Output results:1-3.1415-love document.write (Myarray.join ("")); Output result: What is it? document.write (Myarray.join ("*¥")); Output result: What is it? document.write (Myarray.join ("* &")); Output result: What is it? document.write (Myarray.join ("")); Output result: What is it? Reverse (): Reverses the order of elements in an array document.write (Myarray.reverse ()); Output Results:love,3.1415,1 Slice (< >[,< final): the equivalent of array clipping, not including the end. See here you should associate the substring () and substr () method of Sting objects. are actually similar. var arraynumber = new Array (1,2,3,4,5,6,7,8); &nBsp document.write (Arraynumber.slice (3)); The output results:4,5,6,7,8 document.write (Arraynumber.slice (3,5)); Output:4,5 I made a mistake, I originally wrote the result is 4,5,6, is actually 4, 5. Thanks for a friend's offer. Attention, in fact, the slice method does not include the termination position. document.write (Arraynumber.slice (3,3)); Output result: What is it? document.write (Arraynumber.slice (3,2)); Output result: What is it? document.write (Arraynumber.slice (3,-1)); Output result: What is it? document.write (Arraynumber.slice (-100)); Output result: What is it?? Sort ([< method function): Sort Without method functions, sorted alphabetically, that is, sorted by character encoding, not generally considered numerically sorted. If you have a method function, sort by the method function. Example: code as follows: <script> function Sortnumber (a,b) { return a-b; } var myarray = new Array (3,2,54,23,90,250); document.write ("document.write (" not sorted by sort: ", myarray," < br/> ") document.write (" Default sort Sort value: ", Myarray.sort ()," <br/> ") document.write (" via Sortnumber "() Sort sorted values: ", Myarray.sort (Sortnumber)," <br/> ") </script> result is: without sortThe numeric value of the sort:3,2,54,23,90,250 the default sort order: This I don't know, the main who will remember the character encoding. Value of sort sorted by Sortnumber ():2,3,23,54,90,250 If you change the "A-b" in the Sortnumber method to "B-a", what is the result?