Javascript authoritative guide

Source: Internet
Author: User

1. the array subscript must be a non-negative integer. Otherwise, JavaScript will convert it into a string as the name of the object attribute, instead of defining a new array subscript.

2. adding a new element to the array does not necessarily follow the subscript of the current array. arrays in JavaScript are sparse. For example, a [0] = 10; A [1000] = 99; the interpreter only allocates memory to the array of the 0 and 1000 subtopics.

3. Delete sets an array element as undefined, but the element still exists in this province. To delete an element, you must use an array method, array. the shift () method deletes the first element of the array element, array. the pop () method deletes the last element of the array element, array. splice () Removes elements in a continuous range from an array.

4. Join () method: You can convert all elements in an array into a string or specify a separator.

For example: var A = [1, 2, 3]; var S = A. Join ('-'); alert (s); // "1-2-3"

5. Reverse () method: sorts the inverted array elements and returns the inverted array.

6. sort () method: If no parameter is specified, array elements are sorted alphabetically. If a parameter is to be specified, a function () is input, which returns a number, when a negative number is used, the first parameter is placed in the front, and when a positive number is used, the first parameter is placed in the back, and 0 is returned. Example:

VaR S = ["Huaxing", "xuxiao", "somebody"];

S. Sort (function (a, B ){

Return A. length-b.length;

});

Alert (s); // "xuxiao", "Huaxing", "somebody"

7. Contact () method: concatenate two arrays into an array.

8. Slice () method: the returned result is a segment (slice) or subarray of an array. Its two parameters return the starting and ending points of the fragment to be returned. The returned array contains the elements specified by the first parameter and the elements specified by the second parameter, but does not contain the elements specified by the second parameter. If only one parameter is passed to it, the returned array contains all elements starting from the starting position to the ending of the original number. If either of the two parameters is negative, it specifies the element relative to the last element in the array. -1 specifies the last element of the element.

Example: var A = [1, 2, 3, 4, 5];

A. Slice (); // [, 3]

A. Slice (3); // [4, 5]

A. Slice (1,-1); // [2, 3, 4]

A. Slice (-3,-2); // [3]

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.