inspection

Array.prototype.join

Returns a string formed by concatenating each element, separated by the given string (default ','). Reach for it to build CSV/URL/paths or any delimited string from an array.

arr.join([separator])

Parameters

Parameter Purpose
separator String inserted between elements; defaults to ',' if omitted
return value A string; null/undefined elements become empty strings

Examples

console.log(['a','b','c'].join());

Logs: 'a,b,c'

console.log(['a','b','c'].join(' - '));

Logs: 'a - b - c'

console.log([1, null, 2, undefined, 3].join(','));

Logs: '1,,2,,3' (null and undefined become empty)

console.log([].join(','));

Logs: '' (empty array → empty string)

Gotcha

null and undefined elements render as empty strings, NOT the literals 'null'/'undefined'. Default separator is ',', not '' — use `.join('')` to concatenate without a delimiter.

Related methods

← All JS array methods · TypeScript vs JavaScript