Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Array.prototype.join()

翻譯不完整。請協助 翻譯此英文文件

join() 方法 (method) 將陣列中所有元素 (element) 連接合併成一個字串。

Syntax (語法)

str = arr.join([separator = ','])

Parameters (參數)

separator
可選用。用來隔開陣列中每個元素的字串。如果必要的話,separator 會自動被轉成字串型態。如果未傳入此參數,陣列中的元素將預設用英文逗號隔開。如果 separator 是空字串,合併後,元素間不會有任何字符。

Description (描述)

將所有陣列中的元素轉成字串型態後,連接合併成一個字串。任何 undefined 或 null 的元素都會被視為空字串處理。

Examples (範例)

舉例四種 Join 用法

下方的範例中,首先宣告一個陣列 a,其中有三個元素。接著分別用預設值、逗號、加法號和空字串將陣列連接。

var a = ['Wind', 'Rain', 'Fire'];
var myVar1 = a.join();      // assigns 'Wind,Rain,Fire' to myVar1
var myVar2 = a.join(', ');  // assigns 'Wind, Rain, Fire' to myVar2
var myVar3 = a.join(' + '); // assigns 'Wind + Rain + Fire' to myVar3
var myVar4 = a.join('');    // assigns 'WindRainFire' to myVar4

Specifications (規範)

Specification Status Comment
ECMAScript 1st Edition (ECMA-262) Standard Initial definition. Implemented in JavaScript 1.1.
ECMAScript 5.1 (ECMA-262)
The definition of 'Array.prototype.join' in that specification.
Standard  
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Array.prototype.join' in that specification.
Standard  
ECMAScript 2017 Draft (ECMA-262)
The definition of 'Array.prototype.join' in that specification.
Draft  

Browser compatibility (瀏覽器相容性)

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 1.0 (1.7 or earlier) 5.5 (Yes) (Yes)
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

See also (相關資料)

文件標籤與貢獻者

 此頁面的貢獻者: JamesWen
 最近更新: JamesWen,