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
Array.prototype.concat
Returns a new array formed by joining the source with the provided arrays and/or values (one level of spread). Reach for it to merge arrays without mutating any of them.
Array.prototype.slice
Returns a shallow copy of a portion of the array from start (inclusive) to end (exclusive) without modifying the source. Reach for it to extract a range or to clone an array (`arr.slice()`).
Array.from
Creates a new Array from an iterable or array-like object, optionally mapping each element as it is copied (ES2015). Reach for it to materialize a NodeList, Set, string, or `{length}` array-like into a real array.
Array.prototype.at
Returns the element at the given integer index, supporting negative values that count from the end (ES2022). Reach for it as the clean replacement for `arr[arr.length - 1]`.