JavaScript .join()
Published Jun 21, 2021Updated Oct 8, 2022
Contribute to Docs
The .join() method returns a string representation of array elements concatenated together.
Syntax
array.join(separator);
An optional separator parameter specifies a string or character that goes between each array element in the returned string. Passing an empty string ('') will join all the elements without any characters between them. If a separator is not provided, the array elements will be separated with a comma.
Examples
Joining an array into a string without a separator argument:
const gameObjects = ['rock', 'paper', 'scissors'];const joinNoSeparator = gameObjects.join();const joinWithSeparator = gameObjects.join(' + ');console.log('No separator: ', joinNoSeparator);console.log('With separator: ', joinWithSeparator);
This produces the following output:
No separator: rock,paper,scissorsWith separator: rock + paper + scissors
Codebyte Example
The following example joins an array into a string with an empty string separator argument:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn JavaScript on Codecademy
- Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
- Includes 34 Courses
- With Professional Certification
- Beginner Friendly.115 hours
- Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
- Beginner Friendly.15 hours