Array

Array.prototype.join

Creates and returns a new string by concatenating all elements in an array, separated by commas or a specified separator

Syntax

JavaScript
array.join(separator?)

Parameters

ParameterTypeDescription
separatorstringString used to separate each pair of adjacent elements. Defaults to comma

Return Value

A string with all array elements joined

Examples

Basic Usage
const elements = ['Fire', 'Air', 'Water'];
console.log(elements.join()); // 'Fire,Air,Water'
console.log(elements.join(' - ')); // 'Fire - Air - Water'
Practical Example
const path = ['home', 'user', 'documents'];
console.log(path.join('/')); // 'home/user/documents'
Advanced Usage
const csv = [['Name', 'Age'], ['Alice', '30']];
const rows = csv.map(row => row.join(','));
console.log(rows.join('\n'));

Understanding Array.prototype.join

The Array.prototype.join method in JavaScript creates and returns a new string by concatenating all elements in an array, separated by commas or a specified separator. It belongs to the Array object and is one of the most widely used methods for working with array values in modern JavaScript and TypeScript applications.

The method signature is array.join(separator?). It accepts 1 parameter: separator. When called, it returns a string with all array elements joined. Understanding when and how to use join() helps you write more expressive, readable code.

Common use cases for Array.prototype.join include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like string-split, array-tostring, array-concat, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for Array.prototype.join is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More Array Methods

Other methods in the Array object

Related Tools

More Array Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.