JavaScript String concat()
示例
連線兩個字串
let text1 = "sea";
let text2 = "food";
let result = text1.concat(text2);
自己動手試一試 »
連線兩個字串
let text1 = "Hello";
let text2 = "world!";
let result = text1.concat(" ", text2);
自己動手試一試 »
更多示例見下文。
描述
concat()
方法用於連線兩個或多個字串。
concat()
方法不會更改現有字串。
concat()
方法返回一個新字串。
語法
string.concat(string1, string2, ..., stringX)
引數
引數 | 描述 |
string1, string2, ... stringX | 必需。 要連線的字串。 |
返回值
型別 | 描述 |
一個字串 | 包含組合字串的新字串。 |
更多示例
連線三個字串
let text1 = "Hello";
let text2 = "world!";
let text3 = "Have a nice day!";
let result = text1.concat(" ", text2, " ", text3);
自己動手試一試 »
瀏覽器支援
concat()
是 ECMAScript1 (ES1) 功能。
ES1 (JavaScript 1997) 在所有瀏覽器中都得到完全支援
Chrome | Edge | Firefox | Safari | Opera | IE |
是 | 是 | 是 | 是 | 是 | 是 |