Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Array.prototype.join

Joins array elements into a string.

Available since: ES1

Syntax

array.join(separator)

Parameters

ParameterTypeDescription
separatorstringOptional. The string placed between the elements; a comma by default.

Return value

stringA string of the array elements.

Examples

A list separated by a comma and a space:

console.log(['red', 'green', 'blue'].join(', '));

Output:

red, green, blue

Joining without a separator:

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

Output:

JS

Notes

null and undefined become an empty string. split() does the reverse.

See also

Related recipes

In the tutorial

  • Array methods — How to add and remove array elements in JavaScript: push, pop, shift, unshift, slice, splice, concat and join.

Thanks for reading!

Donate to the site — we work hard for you.