String.prototype.concat()

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

语法

str.concat(string2string3[, ..., stringN])

参数

string2...stringN
和原字符串连接的多个字符串

描述

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

示例

例子:使用 concat

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

var hello = "Hello, ";
console.log(hello.concat("Kevin", " have a nice day.")); /* Hello, Kevin have a nice day. */

性能

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

规范

Specification Status Comment
ECMAScript 3rd Edition (ECMA-262) Standard Initial definition. Implemented in JavaScript 1.2.
ECMAScript 5.1 (ECMA-262)
String.prototype.concat
Standard  
ECMAScript 2015 (6th Edition, ECMA-262)
String.prototype.concat
Standard  

浏览器兼容性

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) (Yes) (Yes) (Yes)
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

相关链接