Array Concat,join and Reverse methods

Source: Internet
Author: User

The Concat () method in the array: Creates and returns a new array that is generated by adding all parameters to the array. It does not modify the array.

If the argument for the concat () operation is an array, then the element in the array is added, not the array.

var arr=[1,2,3var arr1=[4,5,6//[1,2,3,4,5,6]

The Join ("") method in the array is to convert each array element into a string and then concatenate the strings to insert the specified string or symbol between the two elements ...

The argument in parentheses refers to the character or string that is used to separate the elements of an array in the returned string, which is optional. If this argument is omitted, a comma is used as the delimiter.

The return value is:-A string that is generated by converting each element of the array into a string and then connecting the strings to insert a separator string between two elements.

var arr=[' C ', ' Z ', ' y '];console.log (Arr3.join ("+"));  // Convert an array to a string C+z+y

Reverse () Method: Reverses the order of the elements in the array. It does this on the original array, which is to rearrange the elements of the specified array, but does not create a new array. If you have multiple references to an array, you can see the new order of the array elements through all references.

var arr=["Zhang San", "John Doe", "Harry"//["Harry", "John Doe", "Zhang San"]

This should be the case when you arrange the string upside down:

var str= "abcdef";  Console.log (Str.split (//f,e,d,c,b,a

Well, the basic usage of these three methods of the Savior is this, of course, can be used together, just like the last of this small example.

Of course, the situation in the project needs actual practical consideration ... That's it today!

Array Concat,join and Reverse methods

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.