JavaScript String concat() method

Definition and usage

concat() The method concatenates two or more strings.

concat() The method does not change the existing string.

concat() The method returns a new string.

Instance

Example 1

Concatenate two strings:

let text1 = "sea";
let text2 = "food";
let result = text1.concat(text2);

Try it yourself

Example 2

Concatenate two strings:

let text1 = "Hello";
let text2 = "world!";
let result = text1.concat(" ", text2);

Try it yourself

Example 3

Concatenate three strings:

let text1 = "Hello";
let text2 = "world!";
let text3 = "Have a nice day!";
let result = text1.concat(" ", text2, " ", text3);

Try it yourself

Syntax

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

Parameter

Parameter Description
string1, string2, ... stringX Required. The string to be concatenated.

Return value

Type Description
String Contains the new string with the combined strings.

Description

Method concat() Converts all its parameters to strings (if necessary), then concatenates them in order to the string string at the end, returning the concatenated string. Please note thatstring Itself is not modified.

String.concat() With Array.concat() They are very similar. Note that using the '+' operator for string concatenation is usually more convenient.

Browser support

concat() It is an ECMAScript1 (ES1) feature.

All web browsers fully support ES1 (JavaScript 1997):

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Stöd Stöd Stöd Stöd Stöd Stöd

Relaterade sidor

JavaScript-sträng

JavaScript-strängmetoder

JavaScript-strängsökning