Heim  >  Artikel  >  Web-Frontend  >  javascript:拼接字符串函数concat()

javascript:拼接字符串函数concat()

高洛峰
高洛峰Original
2016-11-16 10:39:142865Durchsuche

String.prototype.concat()

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

语法

str.concat(string2, string3[, ..., stringN])

参数

string2...stringN

和原字符串连接的多个字符串

描述

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

示例

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

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

性能

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

浏览器兼容性

全平台支持。


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:初识ReactNächster Artikel:javascript中自定义事件