Array functions of JavaScript

Source: Internet
Author: User

(1) Join function: Converts and joins all elements in an array to a string. Cases:

    

[JavaScript]View Plaincopyprint?
    1. function Joindemo ()
    2. {
    3. var a, b;
    4. A = NewArray (0,1,2,3,4);
    5. b =a.join ("-"); //Delimiter
    6. return (b); //Return to b== "0-1-2-3-4"
    7. }

(2) Length function: Returns the lengths of the array. Cases:

   

[JavaScript]View Plaincopyprint?
    1. function Lengthdemo ()
    2. {
    3. var a, l;
    4. A = NewArray (0,1,2,3,4);
    5. L = a.length;
    6. return (L); //l==5
    7. }

(3) Reverse function: Reverses the order of the array elements. Cases:

   

[JavaScript]View Plaincopyprint?
    1. function Reversedemo ()
    2. {
    3. var a, l;
    4. A = new Array (0,1,2,3,4);
    5. L = A.reverse ();
    6. return (L);
    7. }

(4) sort Function: Reorder the elements of the array. Cases:

    

[JavaScript]View Plaincopyprint?
    1. function Sortdemo ()
    2. {
    3. var a, l;
    4. A = NewArray ("X","y","D", "Z","V","M","R");
    5. L = A.sort ();
    6. return (L);
    7. }

(5) toString Function: Converts an array into a string, concatenated by commas.

(6) valueOf function: The same as the ToString function.

(7) concat function: Connect the other array to the end of the current array.

(8) shift Function: Deletes the first element in the array and returns the value of the deleted element.

(9) pop function: Deletes the last element.

(10) Push function: Adds one or more elements to the tail end and returns the length of the array after the addition.

(11) unshift function: Add one or more elements to the first end

(12) Slice (start,end) function: intercepts a segment element of an array, starting at the end of the array if start is a negative number

Array functions of JavaScript

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.