JavaScript concat()Method

String 对象参考手册JavaScript String Object

Examples

Concatenate two strings:

var str1 = "Hello ";
var str2 = "world!";
var n = str1.concat(str2);

nOutput:

Hello world!

Try it Yourself »

Definition and Usage

The concat() method is used to join two or more strings.

This method does not change the original string, but returns a new string that concatenates two or more strings.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the concat() method


Syntax

string.concat(string1, string2, ..., stringX)

Parameter Values

Parameter Description
string1, string2, ..., stringX Required. One or more string objects to be concatenated into a string.

Return Value

Type Description
String A new string generated after concatenating two or more strings.

Technical Details

JavaScript Version: 1.2


More Examples

Example 2

Concatenate three strings:

var str1="Hello ";
var str2="world!";
var str3=" Have a nice day!";
var n = str1.concat(str2,str3);

nOutput:

Hello world! Have a nice day!

Try it Yourself »


String 对象参考手册JavaScript String Object

Other Extensions