JavaScript Array properties and methods

Source: Internet
Author: User
Tags javascript array

The addition of array elements

1. Arrayt.splice (index,howmany,item1,....., ItemX)

Add/Remove items to/from the array and return the deleted items

2. Array.unshift ()

Adds one or more new elements to the beginning of the array, the elements in the array are automatically moved back, returning the new length of the array

3. Array.push (Newelement1,newelement2,...., newelementx)

Adds one or more new elements to the end of the array and returns the new length of the array

Array element deletion

1. Array.pop ()

Deleting and returning the last element of the array changes the length of the original array

2. Arrayt.splice (index,howmany,item1,....., ItemX)

Add/Remove items to/from the array and return the deleted items

3. Array.shift ()

Removes the first element from the array and returns the value of the first element, changing the length of the original array

Interception and merging of arrays

1. Array.slice (start,end)

Returns the selected element from an existing array

2. Array.concat (Arrayx,arrayx,......, Arrayx)

(Arrayx can be a specific value, or it can be an array object.) can be any number)

Used to connect two or more arrays

var a = [Ocument.write];d (a.concat (4,5)); The result is [1,2,3,4,5] 

copy of Array

1. Array.slice (start,end)

Returns the selected element from an existing array

2. Array.concat (Arrayx,arrayx,......, Arrayx)

(Arrayx can be a specific value, or it can be an array object.) can be any number)

Used to connect two or more arrays

var a = [Ocument.write];d (A.concat (4,5)); The result is [1,2,3,4,5]

Ordering of array elements

1. Array.Sort (sortby) (Soetby optional, must be a function)

Sorting an array element

2. Array.reverse ()

Reverse the order of the array

string of array elements

1. Array.join (separator)

(separator Specifies the delimiter to use.) If this argument is omitted, a comma is used as the delimiter)

Put all the elements of the array into a string. element is delimited by the specified delimiter.

2. Array.tostring ()

Convert an array to a string

JavaScript Array properties and methods

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.