JavaScript's concat () method

Source: Internet
Author: User

Concat ()
method is used to concatenate two or more strings.
The method does not alter the existing array, but only returns a copy of the concatenated array.
Arrayobject.concat (Arrayx,arrayx,......, Arrayx)
The concat () method converts all its arguments to a string, then connects sequentially to the end of the string stringobject and returns the concatenated string. Please note that the Stringobject itself has not been changed.
Tip: Note that using the "+" operator for string connection operations is usually easier.

Example 1
var str1= "Hello"
var str2= "world!"
document.write (Str1.concat (STR2))//Hello world!
document.write (STR1)//Hello

Example 2
var a = [1, ' ABC ', 3];
document.write (A.concat (4,5)); 1,abc,3,4,5
document.write (a)//1,abc,3
document.write (a[1])//ABC

Example 3
var arr = new Array (3)
Arr[0] = 1
ARR[1] = 2
ARR[2] = 3

var arr2 = new Array (3)
ARR2[0] = 4
ARR2[1] = 5
ARR2[2] = 6

var arr3 = new Array (3)
Arr3[0] = 7
ARR3[1] = ' abc '
ARR3[2] = 9

document.write (Arr.concat (ARR2))//1,2,3,7,8,9
document.write (Arr.concat (ARR2,ARR3))//1,2,3,4,5,6,7,abc,9

JavaScript's concat () method

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.