【javascript系列】字符串:拼接字符串函數concat()

String.prototype.concat()segmentfault

concat() 方法將一個或多個字符串與原字符串鏈接合併,造成一個新的字符串並返回,不影響原字符串。瀏覽器

語法

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

參數

string2...stringN

和原字符串鏈接的多個字符串性能

描述

concat 方法將一個或多個字符串與原字符串鏈接合併,造成一個新的字符串並返回。 concat 方法並不影響原字符串。prototype

示例

下面的例子演示如何將多個字符串與原字符串合併爲一個新字符串。code

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

性能

強烈建議使用 賦值操做符(+, +=)代替 concat 方法。參看 幾種評價字符串方法的性能比較。字符串

瀏覽器兼容性

全平臺支持。get

相關文章
相關標籤/搜索