The method array.toString() actually calls array.join() which result in a string concatenated by commas. ref

var array = ['a','b','c','d','e','f'];
document.write(array.toString()); // "a,b,c,d,e,f"

Also, you can implicitly call Array.toString() by making javascript coerce the Array to an string, like:

//will implicitly call array.toString()
str = ""+array;
str = `${array}`;

Array.prototype.join()

The join() method joins all elements of an array into a string.

Arguments:

It accepts a separator as argument, but the default is already a comma ,

str = arr.join([separator = ','])

Examples:

var array = ['A', 'B', 'C'];
var myVar1 = array.join();      // 'A,B,C'
var myVar2 = array.join(', ');  // 'A, B, C'
var myVar3 = array.join(' + '); // 'A + B + C'
var myVar4 = array.join('');    // 'ABC'

Note:

If any element of the array is undefined or null , it is treated as an empty string.

Browser support:

It is available pretty much everywhere today, since IE 5.5 (1999~2000).

References

  • ECMA Specification
  • Mozilla
  • MSDN
Answer from Victor on Stack Overflow
๐ŸŒ
Reddit
reddit.com โ€บ r/javascripttips โ€บ how do i convert an array to a string with commas in javascript
r/JavaScriptTips on Reddit: How do I convert an array to a string with commas in JavaScript
April 13, 2023 -

In JavaScript, you can convert an array to a string with commas using the join()
method.

The join() method returns a string that concatenates all the elements of an array, separated by the specified separator, which in this case is a comma.

Here is an example:

const array = ['apple', 'banana', 'orange'];
const string = array.join(', ');
console.log(string); 

// output: "apple, banana, orange"

In this example, we first define an array of three fruits. Then we use the join()
method with a comma and a space as the separator to create a string that lists all the fruits with a comma and a space between each one.

You can replace the comma and space separator with any other separator you like, such as a hyphen, a semicolon, or a newline character.

It's important to note that the join() method only works on arrays, and it will throw an error if you try to use it on any other type of object.

Click here to learn more ways to Convert Array to String with Commas in JS

๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Array โ€บ join
Array.prototype.join() - JavaScript | MDN
The join() method of Array instances creates and returns a new string by concatenating all of the elements in this array, separated by commas or a specified separator string. If the array has only one item, then that item will be returned without using the separator.
๐ŸŒ
Medium
medium.com โ€บ coding-at-dawn โ€บ how-to-convert-an-array-to-a-string-with-commas-in-javascript-79e212506c2
How to Convert an Array to a String with Commas in JavaScript | by Dr. Derek Austin ๐Ÿฅณ | Coding at Dawn | Medium
January 5, 2023 - โ€œThe join() method creates and returns a new string by concatenating all of the elements in an array (or an array-like object), separated by commas or a specified separator string.โ€ โ€” MDN Docs
๐ŸŒ
ReqBin
reqbin.com โ€บ code โ€บ javascript โ€บ 98ugueow โ€บ javascript-array-join-example
How do I join array elements in JavaScript?
The array.join(separator) method in JavaScript allows you to concatenate all the elements of an array into a single string. By default, array elements will be separated by "," (comma); this behavior can be changed by passing the necessary separator ...
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ jsref_join.asp
JavaScript Array join() Method
The default is comma (,). ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com ยท If you want to report an error, or if you want to make a suggestion, send us an ...
๐ŸŒ
daily.dev
daily.dev โ€บ home โ€บ blog โ€บ get into tech โ€บ join method javascript: faqs answered
Join Method JavaScript: FAQs Answered
December 22, 2025 - The join() method in JavaScript combines all the pieces of an array into one string. It puts something called a separator between each piece. By default, this separator is a comma, but you can choose whatever you like, such as a space or a dash.
Find elsewhere
Top answer
1 of 9
65

One option would be to pop the last item, then join all the rest by commas, and concatenate with and plus the last item:

const input = ['one', 'two', 'three', 'four'];
const last = input.pop();
const result = input.join(', ') + ' and ' + last;
console.log(result);

If you can't mutate the input array, use slice instead, and if there might only be one item in the input array, check the length of the array first:

function makeString(arr) {
  if (arr.length === 1) return arr[0];
  const firsts = arr.slice(0, arr.length - 1);
  const last = arr[arr.length - 1];
  return firsts.join(', ') + ' and ' + last;
}

console.log(makeString(['one', 'two', 'three', 'four']));
console.log(makeString(['one']));

2 of 9
57

Starting in V8 v7.2 and Chrome 72, you can use the sweet Intl.ListFormat API. It will also take care of localizing your list when requested, which might be of great help if you need it.

const lf = new Intl.ListFormat('en');

console.log(lf.format(['Frank']));
// โ†’ 'Frank'

console.log(lf.format(['Frank', 'Christine']));
// โ†’ 'Frank and Christine'

console.log(lf.format(['Frank', 'Christine', 'Flora']));
// โ†’ 'Frank, Christine, and Flora'

console.log(lf.format(['Frank', 'Christine', 'Flora', 'Harrison']));
// โ†’ 'Frank, Christine, Flora, and Harrison'

// You can use it with other locales
const frlf = new Intl.ListFormat('fr');

console.log(frlf.format(['Frank', 'Christine', 'Flora', 'Harrison']));
// โ†’ 'Frank, Christine, Flora et Harrison'

You can even specify options to make it a disruption and use "or" instead of "and", or to format units such as "3 ft, 7 in".

It's not very widely supported as of writing, so you might not want to use it everywhere.

References
The Intl.ListFormat API - Google Developers
V8 release v7.2

๐ŸŒ
CoreUI
coreui.io โ€บ answers โ€บ how-to-convert-an-array-to-a-string-in-javascript
How to convert an array to a string in JavaScript ยท CoreUI
September 23, 2025 - If no separator is provided, join() defaults to using commas. The method works with any array content and automatically converts non-string elements to strings during the process.
๐ŸŒ
Board Infinity
boardinfinity.com โ€บ blog โ€บ array-join-in-javascript
Array Join() in JavaScript | Board Infinity
January 2, 2025 - The use of javascript array join() is to combine all the elements of an array and form a new string out of the array.
๐ŸŒ
Flexiple
flexiple.com โ€บ javascript โ€บ javascript-array-join
JavaScript Array join() Method - Flexiple
The JavaScript Array join() method ... between the elements of the array in the new string. If no separator is specified, the elements are joined with a comma by default....
Top answer
1 of 2
23

When JavaScript coerces an array to a string, it actually call: .join(',') on the array. So you're actually going to be getting better performance with .join(',') manually as opposed to leaving it up to the interpreter to notice you're coercing the array. So: x + ',' + y is the fastest, [x, y].join(',') is the best practice(since it makes it easier to modify the behavior), and [x, y] is a tiny bit slower than manually calling .join and can be unreadable at times, but it's more convenient.

2 of 2
5

the short answer: use array.join.

the long answer:

First off, concatenation isn't faster than using array.join(), it's slower. this is because each time you concatenate you destroy two strings and create a new one.

take the following code:

<script>
function concat(){
var txt = '';
for (var i = 0; i < 1000000; i++){
txt =+ i + ',';
}
}

function arr(ar){
var txt = 'asdf' + ar;
}

ar = [];
for (var i = 0; i < 1000000; i++) {
ar.push(i);
}

concat();

arr(ar);

alert('done!');
</script>

and paste it into an html file. Then profile it. On my machine (core i7EE, 16GB RAM, SSD disks, IE9), arr() takes 0ms and concat() takes 12ms. Keep in mind this is over a million iterations (this same test would be quite different on IE6, concat() would take seconds).

Second, concatenation will take the same as array.join when having only two values. So for your example, from a performance perspective, they're both equivalent. if you take the above code and change the 1000000 to 4, both concat and arr take 0ms to execute. this means the difference for your particular flow is either inexistent or so negligible it doesn't show up in a profile.

Third, modern browsers optimize string concatenation using array.join() anyways, so the discussion is probably moot from a performance point of view.

That leaves us with style. Personally, I wouldn't use the first form because I don't like manually concatenating strings (when you've got 2 vars it's rather straightforward, but what if you have 10 vars? that'll make a really long line of code. And what if you receive an array with n values, in comes a for loop). I wouldn't use the second form either because, as pointed out in another answer, the value is coerced to a string, and that means some implicit transformation is going on. The problem here is the implicit part. I know now arrays are joined with a comma when coerced, but what happens if the spec changes, or some genius decides to change the toString implementation of Array.prototype in your codebase? just for fun run this in jsfiddle:

Array.prototype.toString = function() {
return 'not the expected result!';
}

alert([1, 2]);

Can you guess what the answer will be? (the above code will execute the same kind of conversion for the array as your code. coercion via the toString() method)

if you use array.join(','); you'll be futureproofing your code by stating that 1) your array will be joined regardless of the toString implementation and 2) it will be joined with a comma.

๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ create-a-comma-separated-list-from-an-array-in-javascript
Create a Comma Separated List from an Array in JavaScript | GeeksforGeeks
December 28, 2024 - The _.join(array) function from Lodash is used to join the elements of the array into a string, with the default separator being a comma.
๐ŸŒ
Code.mu
code.mu โ€บ en โ€บ javascript โ€บ manual โ€บ array โ€บ join
The join method - concatenation of array elements into a string in JavaScript
If it is not specified, a comma will be used as a separator by default. If you want to merge array elements without a separator - specify it as an empty string ''. ... Let some array be given. Let's concatenate the elements of this array into a string with the separator '-':
๐ŸŒ
YouTube
youtube.com โ€บ watch
Convert Array to Comma Separated String JavaScript - YouTube
Certainly! Converting an array to a comma-separated string in JavaScript can be achieved in several ways. There are 3 ways to convert an array to a comma-sep...
Published ย  December 19, 2023
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript-array-join-method
JavaScript Array join() Method | GeeksforGeeks
July 12, 2024 - The JavaScript Array join() Method is used to join the elements of an array into a string. The elements of the string will be separated by a specified separator and its default value is a comma(,).
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ how-to-concatenate-strings-in-an-array-in-javascript
How to Concatenate Strings in an Array in JavaScript
May 16, 2023 - The easiest way to append all elements in an array into one is the join() method of the Array class. It joins all the elements into a string with the given optional delimiter. If you omit the delimiter - it's set to a comma (,):
๐ŸŒ
javaspring
javaspring.net โ€บ blog โ€บ how-to-convert-array-into-comma-separated-string-in-javascript
How to Convert an Array to a Comma-Separated String in JavaScript: Quick and Easy Method โ€” javaspring.net
The simplest and most efficient way to convert an array to a comma-separated string in JavaScript is using the built-in Array.prototype.join() method. The join() method concatenates all elements of an array into a single string, separated by ...