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