Javascript array Functions

Source: Internet
Author: User

Javascript array Functions

(1)JoinFunction: converts and concatenates all elements in the array into a string. Example:

    

Function JoinDemo () {var a, B; a = newArray (0, 1, 2, 3, 4); B =. join ("-"); // separator return (B); // return B = "0-1-2-3-4 "}

(2)LengthFunction: returns the length of the array. Example:

   

  function LengthDemo()     {      var a, l;      a = newArray(0,1,2,3,4);      l = a.length;      return(l);  //l==5     }

(3)ReverseFunction: reverses the order of array elements. Example:

   

   function ReverseDemo()    {     var a, l;     a = new Array(0,1,2,3,4);     l = a.reverse();     return(l);    }

(4)SortFunction: sorts array elements. Example:

    

 function SortDemo()     {      var a, l;      a = newArray("X" ,"y" ,"d", "Z","v","m","r");      l = a.sort();      return(l);     }

(5)ToStringFunction: converts an array to a string connected by commas.

(6)ValueOfFunction: Same as the toString function.

(7)ConcatFunction: connects other arrays to the end of the current array.

(8)ShiftFunction: Delete the first element in the array and return the value of the deleted element.

(9)PopFunction: Delete the last element.

(10)PushFunction: add one or more elements to the end and return the length of the added array.

(11)UnshiftFunction: adds one or more elements to the beginning.

(12)Slice (start, end)Function: truncates an array element. If start is a negative number, it starts from the end of the 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.