From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../global_objects/string/concat/index.html | 83 ++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 files/zh-cn/web/javascript/reference/global_objects/string/concat/index.html (limited to 'files/zh-cn/web/javascript/reference/global_objects/string/concat/index.html') diff --git a/files/zh-cn/web/javascript/reference/global_objects/string/concat/index.html b/files/zh-cn/web/javascript/reference/global_objects/string/concat/index.html new file mode 100644 index 0000000000..ee2d8dd06d --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/string/concat/index.html @@ -0,0 +1,83 @@ +--- +title: String.prototype.concat() +slug: Web/JavaScript/Reference/Global_Objects/String/concat +tags: + - JavaScript + - Method + - Prototype + - String +translation_of: Web/JavaScript/Reference/Global_Objects/String/concat +--- +
{{JSRef}}
+ +

concat() 方法将一个或多个字符串与原字符串连接合并,形成一个新的字符串并返回。

+ +

语法

+ +
str.concat(str2, [, ...strN])
+ +

参数

+ +
+
str2 [, ...strN]
+
需要连接到 str 的字符串。
+
+ +

返回值

+ +

一个新的字符串,包含参数所提供的连接字符串。

+ +

描述

+ +

concat 方法将一个或多个字符串与原字符串连接合并,形成一个新的字符串并返回。 concat 方法并不影响原字符串。

+ +

如果参数不是字符串类型,它们在连接之前将会被转换成字符串。

+ +

性能

+ +

强烈建议使用赋值操作符+, +=)代替 concat 方法。

+ +

示例

+ +

使用 concat

+ +

下面的例子演示如何将多个字符串与原字符串合并为一个新字符串

+ +
let hello = 'Hello, '
+console.log(hello.concat('Kevin', '. Have a nice day.'))
+// Hello, Kevin. Have a nice day.
+
+let greetList = ['Hello', ' ', 'Venkat', '!']
+"".concat(...greetList)  // "Hello Venkat!"
+
+"".concat({})    // [object Object]
+"".concat([])    // ""
+"".concat(null)  // "null"
+"".concat(true)  // "true"
+"".concat(4, 5)  // "45"
+ +

规范

+ + + + + + + + + + + + +
Specification
{{SpecName('ESDraft', '#sec-string.prototype.concat', 'String.prototype.concat')}}
+ +

浏览器兼容性

+ +

{{Compat("javascript.builtins.String.concat")}}

+ +

相关链接

+ + -- cgit v1.2.3-54-g00ecf