JavaScript Learning notes first week array

Source: Internet
Author: User

Javascript first week

Array Array

Create an array

Customizing how and how to instantiate

Working with arrays

1 , Join ()

The Join method is to concatenate the elements in the array into strings. Parameters are optional. The parameter is the connector. is empty, the parameter is a comma.

2 , reverse ()

The reverse method is to reverse the order of the elements in the array.

3 , sort ()

The sort method is to sort the elements in the array. Default no parameter is ordered in ASCII order. can be a parameter. This parameter is a comparison function, and the comparison function has two parameters.

4 , concat ()

Merges the array and parameters into a new array and returns. Parameters can be single or multiple elements, or they can be single or multiple arrays.

5 , Slice ()

Returns a sub-array of the specified array, as with concat, without altering the original array.

There are two parameters. Specify the start and end positions. If all two parameters are specified, the semi-open interval ([Begin,end)) includes the start position specified by the first parameter, but does not include the end position specified by the second parameter.

If the second parameter is not specified, it is directly to the end.

If the argument is negative, it is relative to the position of the last element. -1 is the last element.

6 , Splice ()

Splice is the method of inserting or deleting elements in an array. Unlike concat (), slice (), he directly manipulated the original array that called him.

The first parameter specifies the starting position of the insertion or deletion

The second parameter specifies the number of elements to delete. If you do not write, delete to the end

The argument for any number after the third is the element that specifies the insertion.

Returns an array of elements that were deleted.

Splice () can realize all the requirements of adding and deleting the array.

7 , push ()

The push () method adds one or more elements to the tail of the array. and returns the new length of the array. Change the original array

8 , pop ()

The Pop () method and the push () method, in contrast, remove an element at the tail. Returns the deleted element. Change the original array

9 , unshift ()

Unshift () and Shift () are similar to the push () and Pop () methods. The difference is in the array head operation. Change the original array

Ten , shift ()

Shift () Instead, delete an element in the head. and returns the deleted element.

One , toString ()

String the array. Split with commas. Equivalent to join (",");

JavaScript Learning notes first week array

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.