JavaScript statement semantics Daquan (4)

Source: Internet
Author: User
Tags array length array to string

1. Var arr1=new Array (2)

var arr2=new Array ()

var arr3=new Array ("A", "B")

var arr4=["A", "B"]

All of the above are declarations of arrays

2. Arrays of various methods--

Length//Lengths

Push (item)//Adds a new element to the end of the array and returns the length of the new array

Unshift (item)//Adds a new element to the beginning of the array and returns the array length

Splice ()

  

  Arrayobject.splice (index,howmany,item1,....., ItemX)

Arr.splice (1,0, "x")//1 is the index, 0 special code, which represents the addition of instructions, X is the deletion of 0 elements, and with the subsequent "X" added in

var col=arr.splice ("X")

The splice () method deletes 0 or more elements starting at index and replaces the deleted elements with one or more values declared in the argument list. This means that 2 elements are removed from the 2nd element and replaced with an "X".

Pop ()//Remove last element

Shift ()//Remove the first element, the array element is automatically moved forward

Concat ()//Connect multiple arrays to return a new connected array

Slice (start,end)//Returns the part of an array as an array, noting that the element of end is not included, and if End is omitted, all subsequent elements are copied

Reverse ()//array rollover

Sort ()//sorting, inside can also have function, function value is greater than 0 when start element interchange--

Arr.sort (Function (v1, v2) {return v1-v2})

IndexOf ()//returns the position where the parameter appears, starting at 0, and returning when it does not exist-1

Split ()//split the string according to the parameter (all the parameters in the string disappear), make up the array

Join ()//from array to string, use parameters to concatenate each element

JavaScript statement semantics Daquan (4)

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.