Home > Article > Web Front-end > javascript: concatenating string function concat()
String.prototype.concat()
concat() method connects and merges one or more strings with the original string to form a new string and return it, without affecting the original string.
Syntax
str.concat(string2, string3[, ..., stringN])
Parameters
string2...stringN
Multiple strings connected to the original string
Description
concat method combines one or more strings with the original string to form a new string and returns it. The concat method does not affect the original string.
Example
The following example demonstrates how to merge multiple strings with the original string into a new string.
var hello = "Hello, "; console.log(hello.concat("Kevin", " have a nice day.")); /* Hello, Kevin have a nice day. */
Performance
It is strongly recommended to use assignment operators (+, +=) instead of concat method.
Browser compatibility
Full platform support.