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)

Parameters

Parameters 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), and then concatenates them in order to the string string at the end, returns the concatenated string. Please note thatstring itself is not modified.

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

Browser support

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

All browsers fully support ES1 (JavaScript 1997):

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Υποστήριξη Υποστήριξη Υποστήριξη Υποστήριξη Υποστήριξη Υποστήριξη

Σελίδες σχετικές

String του JavaScript

Μέθοδοι String του JavaScript

Αναζήτηση String του JavaScript