A common method for converting a method array to a string with a JS array

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

1 Array to string

You need to concatenate an array element with a character into a string, the sample code is as follows:

var A, b;a = new Array (0,1,2,3,4), B = A.join ("-");

Second, string to array

The implementation method is to cut a string into several strings by one character and return as an array, with the sample code as follows:

var s = "abc,abcd,aaa";

SS = S.split (",");//decomposition at each comma (,).


POP Delete last item

Deletes the last item and returns the value of the deleted element, or returns Undefine if the array is empty

shift Deletes the first item

Deletes the first item of the original array and returns the value of the deleted element; Returns undefine if the array is empty

push is added to the last

and returns the new array length;

Unshift added to the front

and returns the new array length;

Reverse Array Rollover

and returns the original array after flipping the original array, flipping the

indexof array Element index

and returns the element index, no return-1, index starting from 0

Slice intercept (slice) array to get intercepted array

Returns a new array of entries from the original array specifying the starting index (contained) to the end index (not included), the original array of wood changes, index starting from 0

Splice splicing array The original array changes can be implemented shift before deletion, pop after deletion, unshift before the increase, with push after the same effect

Returns the array of elements of the splice, the original array changes, and the index starts at 0

Concat Array Merging

Returns the merged new array, the original array of wood changes

A common method for converting a method array to a string with a JS 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.