Join two strings:
let text1 = "sea";
let text2 = "food";
let result = text1.concat(text2);
Try it Yourself »
Join two strings:
let text1 = "Hello";
let text2 = "world!";
let result = text1.concat(" ", text2);
Try it Yourself »
More examples below.
The concat()
method joins two or more strings.
The concat()
method does not change the existing strings.
The concat()
method returns a new string.
string.concat(
string1,
string2, ...,
stringX)
Parameter | Description |
string1, string2, ... stringX |
Required. The strings to be joined. |
Type | Description |
A string | A new string containing the combined strings. |
Join three strings:
let text1 = "Hello";
let text2 = "world!";
let text3 = "Have a nice day!";
let result = text1.concat(" ", text2, " ", text3);
Try it Yourself »
concat()
is an ECMAScript1 (ES1) feature.
ES1 (JavaScript 1997) is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!