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月.
join() 方法會將陣列(或一個類陣列(array-like)物件)中所有的元素連接、合併成一個字串,並回傳此字串。
用來隔開陣列中每個元素的字串。如果必要的話,separator 會自動被轉成字串型態。如果未傳入此參數,陣列中的元素將預設用英文逗號(「,」)隔開。如果 separator 是空字串,合併後,元素間不會有任何字元。
一個合併所有陣列元素的字串。假如 arr.length 為 0,將回傳空字串。
將所有陣列中的元素轉成字串型態後,連接合併成一個字串。任何 undefined 或 null 的元素都會被視為空字串處理。
下方的範例中,首先宣告一個陣列—a,其中有三個元素。接著分別用:預設值、逗號、加號和空字串將陣列連接。
下方的範例將合併一個類陣列(array-like)物件(arguments),藉由 Function.prototype.call 來呼叫 Array.prototype.join。
| ECMAScript® 2027 Language Specification # sec-array.prototype.join |
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.