concat method
The concat
method combines
given strings. The number of strings
to concatenate is not limited. In fact,
the action of this method is similar to
the operation '+'
for string
concatenation.
Syntax
string.concat(another string, and another string, and another...);
Example
Let's use the concat
method
to merge three strings into one:
let str1 = 'a';
let str2 = 'b';
let str3 = 'c';
let res = str1.concat(str2, str3);
console.log(res);
The code execution result:
'abc'
Example
You can apply the method to an empty string. In this case, all the strings to be concatenated will be passed as the method parameters:
let str1 = 'a';
let str2 = 'b';
let str3 = 'c';
let res = ''.concat(str1, str2, str3);
console.log(res);
The code execution result:
'abc'
See also
-
the
concat
method
that concatenates arrays into one