2-javascript Array Object (array)

Source: Internet
Author: User
Tags javascript array

JavaScript Array Object

1. Array creation:

(1) using the array constructor

(2) array literal notation

2. Array Method:

Here are a few important array prototyping methods:

1) Join ()

Join (Separator): Sets the element group of the array as a string, separator as a delimiter, or by default with a comma delimiter, which receives only one argument: the delimiter.

2) push () and pop ()

Push (): can accept any number of arguments, add them to the end of the array one by one, and return the length of the modified array.

Pop (): Removes the last item at the end of the array, reduces the length value of the array, and then returns the item that was removed. 4

3) Shift () and unshift ()

Shift (): Deletes the first item of the original array and returns the deleted element, or returns undefined if the array is empty.

Unshift (): Adds a parameter to the beginning of the original array, returning the length of the array.

4) sort ()

Sort (): Arranges array items in ascending order-minimum at the front, maximum at the last face.

When sorting, the sort () method invokes the ToString () transformation method for each array item, and then compares the resulting string to determine how to sort.

5) Reverse ()

Reverse (): Reverses the order of the array items.

6) concat ()

Concat (): Adds a parameter to the original array, which creates a copy of the current array, adds the received parameter to the end of the copy, and finally returns the newly constructed array. Without passing arguments to the concat () method, it simply copies the current array and returns a copy.

7) Slice ()

Slice (): Returns a new array that consists of the entries from the original array that specify the starting subscript to the end subscript. The slice () method can accept one or two parameters, that is, to return the starting and ending positions of an item. In the case of only one argument, the slice () method returns all items starting at the specified position of the parameter to the end of the current array. If there are two parameters, the method returns the item between the start and end positions--but not the end position.

8) IndexOf () and LastIndexOf ()

IndexOf (): Receives two parameters: the subparagraphs (optional) to find indicates the index at which to find the starting point. Where you start looking backwards from the beginning of the array (position 0).
LastIndexOf: Receives two parameters: the subparagraphs (optional) to find indicates the index at which to find the starting point. Where you start looking forward from the end of the array.

Both of these methods return the position of the item you are looking for in the array, or return it if it is not found. 1. The congruent operator is used when comparing the first argument to each item in the array.

Not finished, to be continued ....

2-javascript Array Object (array)

Related Article

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.