concat()
方法将一个或多个字符串与原字符串连接合并,形成一个新的字符串并返回。
str.concat(string2, string3[, ..., 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
方法。参看 性能测试(perfomance test)。
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 |
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) |