5. Entry 5: javascript array objects

Source: Internet
Author: User

An array is a unique set object in javascript. The test code is as follows:


<Script type = "text/javascript"> var as0 = new Array (); // instantiate an empty Array object var as1 = [5, 2, 4]; // instantiate and assign the value as0 [0] = 123; // use the access method as0 [1] = 45; // traverse 1 for (var I = 0; I <as0.length; I ++) {policnet. write (as0 [I]);} // traverse 2 for (var I in as1) {document. write (as1 [I]);} // sort in ascending order) as1.sort (); // reverse as1.reverse (); // append the new element as1.push (56 ); // Delete the as1.splice (1, 2) element at the beginning of the second element. </script>

More methods of arrays are shown in the table below:

Method Description FF IE
Concat () Concatenate two or more arrays and return results. 1 4
Join () Put all elements of the array into a string. The elements are separated by the specified delimiter. 1 4
Pop () Delete and return the last element of the array 1 5.5
Push () Add one or more elements to the end of the array and return a new length. 1 5.5
Reverse () The order of elements in the array is reversed. 1 4
Shift () Delete and return the first element of the array 1 5.5
Slice () Returns the selected element from an existing array. 1 4
Sort () Sorts elements of an array. 1 4
Splice () Delete elements and add new elements to the array. 1 5.5
ToSource () Returns the source code of the object. 1 -
ToString () Converts an array to a string and returns the result. 1 4
ToLocaleString () Converts an array to a local array and returns the result. 1 4
Unshift () Add one or more elements to the beginning of the array and return a new length. 1 6
ValueOf () Returns the original value of the array object. 1 4


This article from the "Yu yu" blog, please be sure to keep this source http://johnyu.blog.51cto.com/7838287/1300131

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.