[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Array/join [Back]  [Original]

Array.prototype.join() - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

Array.prototype.join()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 20157.

join() array-like

In this article

const elements = ["Fire", "Air", "Water"];

console.log(elements.join());
// Expected output: "Fire,Air,Water"

console.log(elements.join(""));
// Expected output: "FireAirWater"

console.log(elements.join("-"));
// Expected output: "Fire-Air-Water"

arr.join([separator])

separator

separator , separator

arr.length 0

undefined null

a

js
var a = ["Wind", "Rain", "Fire"];
a.join(); // 'Wind,Rain,Fire'
a.join(", "); // 'Wind, Rain, Fire'
a.join(" + "); // 'Wind + Rain + Fire'
a.join(""); // 'WindRainFire'

array-like

array-likearguments Function.prototype.call Array.prototype.join

js
function f(a, b, c) {
  var s = Array.prototype.join.call(arguments);
  console.log(s); // '1,a,true'
}
f(1, "a", true);
//expected output: "1,a,true"

Specification
ECMAScript 2027 LanguageSpecification
# sec-array.prototype.join


Web Proxy Viewer  |  New URL  |  Original Page