join()

ES3+

Creates and returns a new string by concatenating all elements in an array.

Syntax

array.join(separator)

Parameters

separator string optional

String to separate each element (default: comma)

Return Value

string

A string with all array elements joined

Examples

JavaScript
const words = ['Hello', 'World'];
console.log(words.join(' '));
console.log(words.join('-'));
Output:
// 'Hello World' 'Hello-World'

Related Methods