Get to know MDN better
此頁面由社群從英文翻譯而來。了解更多並加入 MDN Web Docs 社群。
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
concat() 會將呼叫此方法的字串以及作為參數傳遞進此方法的字串串接在一起,並將串接結果作為一個新的字串回傳。
要串接到 str 的字串,可以傳入一個至多個。
此方法會回傳一個新的字串,由呼叫此方法的字串及作為參數傳入的字串組合而成。
concat() 會將那些作為參數的字串串接在呼叫此方法的字串後面,並作為一個新的字串回傳。 對於原先的字串、或是回傳的字串做修改,不會讓他們的值互相影響。
如果傳入的參數不是字串型別,那在串接前會先將該參數轉換成字串。
對於字串的串接,強烈建議直接使用運算子 assignment operators 來達成, 像是 + 及 +=,而不是使用 concat() 方法。
以下的例子示範如何將那些給定的字串組合成新的字串。
| ECMAScript® 2027 Language Specification # sec-string.prototype.concat |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2025年7月14日 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.