Explore JavaScript----common methods for arrays

Source: Internet
Author: User

Conversion to String:

Str.split (","): divides a string into commas, returning an array;

Arr.join (","): Returns a string with all array elements separated by the specified delimiter, similar to ToString ();

These two methods are just the opposite.

The operation of the first-lowest array:

Arr.shift (): Removes and returns the first element;

Arr.unshift (a): Add a element at the first bit to return the length of the new array;

Arr.pop (): Removes and returns the last element;

Arr.push (a): Add a element at the last bit to return the length of the new array;

array element increment, delete, change:

Concat () connection array

var arr=[1,2,3,4]

Arr.concat (arr): return [1,2,3,4,1,2,3,4]; attach a copy of arr and arr, or Arr.concat (arr,arr2,..., Arrx);

Arr.concat (5,6): return [1,2,3,4,5,6];

Splice () splice an array, splice () at least two parameters (but the browser can also display a parameter)

Arr.splice (Index,howmany,ele1,ele2,...): Allows arr array to be deleted or added from the index position, delete howmany elements (all after the empty index is deleted), add Ele1,ele2 from the index bit ..., Returns the number of deleted arrays, but Arr becomes the new array, so the return value! = new arr:

Arr.splice (1) return [2,3,4];

Arr.splice [2,3], and a=[1,3,4];

Note: Distinguishing Arr.slice (), splice () will change the array, slice () will not, slice (1) return [3,4];slice] return [2], i.e. slice (star,end) but the returned arrays do not contain an end-bit element;

Explore JavaScript----common methods for arrays

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.