string中concat
字符串concat()方法 (String concat() Method)
concat() is a string method in JavaScript, it is used to concatenate (join) two or more strings and returns a new joined string.
concat()是JavaScript中的字符串方法,用于连接(联接)两个或多个字符串并返回新的联接字符串。
Syntax:
句法:
String.concat(string1, string2, ...);
It accepts string(s) and returns new string (which is joined string with the main string).
它接受字符串并返回新字符串(该字符串与主字符串连接在一起)。
Examples:
例子:
Input:
str1 = "IncludeHelp"
str2 = ".com"
Function call: str1.contact(str2);
Output:
"IncludeHelp.com"
Input:
str1 = "Hello"
str2 = " " //space
str3 = "World!"
Function call: str1.contact(str2, str2);
Output:
"Hello World!"
Code:
码:
<html>
<head>
<title>JavaScipt Example</title>
</head>
<body>
<script>
var str1 = "IncludeHelp";
var str2 = ".com";
document.write(str1.concat(str2) + "<br>");
str1 = "Hello";
str2 = " ";
var str3 = "World!";
document.write(str1.concat(str2, str3) + "<br>");
</script>
</body>
</html>
Output
输出量
IncludeHelp.com
Hello World!
翻译自: https://www.includehelp.com/code-snippets/string-concat-method-with-example-in-javascript.aspx
string中concat