try

array.reduce( (s,x,i) => s+(i>0 ? separator : '') + (x==null ? '' : x), '') 

Show code snippet

function myJoin(array, separator=',') { 
  return array.reduce( (s,x,i) => s+(i>0 ? separator : '') + (x==null ? '' : x), '') 
}

console.log( myJoin(['a', 'b', 'c'], '+') ); 
console.log( myJoin(['Peter', 'Paul', 'Mary']) );
console.log( myJoin(['hello', undefined, 'world'], '-') );
Run code snippetEdit code snippet Hide Results Copy to answer Expand

We use here standard js functionalities: arrow functions, array reduce and ternary operator. If i>0 (not true only for first element) we add separator to output string s. If x is undefined or null we add to s empty string - or x value in other case.

Answer from Kamil Kiełczewski on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › join
Array.prototype.join() - JavaScript - MDN Web Docs
The join() method of Array instances returns a new string that is the concatenation of all elements in this array, separated by commas or a specified separator string. If the array has only one item, that item's stringification is returned without using the separator.
Discussions

How do I convert an array to a string with commas in JavaScript
...you get a better, more thorough explanation here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join More on reddit.com
🌐 r/JavaScriptTips
1
4
April 13, 2023
How to convert array into comma separated string in javascript - Stack Overflow
I have an array: a.value = [a,b,c,d,e,f] How can I convert to comma-seperated string like: a.value = "a,b,c,d,e,f" More on stackoverflow.com
🌐 stackoverflow.com
How to convert array into string without comma and separated by space in javascript without concatenation? - Stack Overflow
1 javascript: How to convert a array of string into a pure string that concatenate the items separated by comma? ... 0 How to convert array into string without comma and separated by space in javascript without using .join()? More on stackoverflow.com
🌐 stackoverflow.com
Easy way to turn JavaScript array into comma-separated list? - Stack Overflow
I have a one-dimensional array of strings in JavaScript that I'd like to turn into a comma-separated list. Is there a simple way in garden-variety JavaScript (or jQuery) to turn that into a comma- More on stackoverflow.com
🌐 stackoverflow.com
🌐
ReqBin
reqbin.com › code › javascript › ot8wzla9 › javascript-array-to-string-example
How do I convert array to string in JavaScript?
November 21, 2023 - To convert an array to a string using a separator between elements in JavaScript, you can use the array.join(separator) method: JavaScript Convert Array to String with Separator Example
🌐
daily.dev
daily.dev › home › blog › webdev › join method javascript: faqs answered
Join Method JavaScript: FAQs Answered | daily.dev
May 25, 2026 - It helps you change a list of things into a single line of text. Here's what to remember: join() makes a string from an array by putting a separator, like a comma, between each part. You can pick any separator you want, though.
🌐
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

🌐
CodingNomads
codingnomads.com › javascript-array-to-string-conversion
JavaScript Array-String Conversion
The join() method can also be used to convert an array to a string with a custom 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 - One of JavaScript’s most helpful built-in array methods is .join() (Array.prototype.join()), which returns a string primitive. “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
Find elsewhere
🌐
W3Schools
w3schools.com › jsref › jsref_join.asp
JavaScript Array join() Method
The join() method does not change the original array. Any separator can be specified. The default is comma (,). ... Coding fundamentals as bite-sized lessons and challenges. ... If you want to use W3Schools services as an educational institution, ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › toString
Array.prototype.toString() - JavaScript - MDN Web Docs
The toString method of arrays calls join() internally, which joins the array and returns one string containing each array element separated by commas. If the join method is unavailable or is not a function, Object.prototype.toString is used instead, returning [object Array]. js · const arr ...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › convert-array-to-string-in-javascript
Convert Array to String in JavaScript - GeeksforGeeks
July 23, 2025 - The String() method converts the array elements to string and then concatenates them with commas as a separator.
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-convert-array-to-comma-separated-string
Convert Array to String (with and without Commas) in JS | bobbyhadz
The Array.join() method will return a string where all of the array elements are joined with a comma separator.
🌐
Code.mu
code.mu › en › javascript › manual › array › join
The join method - concatenation of array elements into a string in JavaScript
The join method concatenates all array elements into a string with the specified separator in JavaScript.
🌐
Altcademy
altcademy.com › blog › how-to-convert-array-to-string-in-javascript
How to convert array to string in JavaScript - Altcademy.com
August 29, 2023 - As you can see, the join() function can handle nested arrays quite well, converting all elements to a string and separating them with commas. Transforming arrays into strings in JavaScript can be thought of as transforming a line of separate words into a complete sentence.
🌐
ReqBin
reqbin.com › code › javascript › 98ugueow › javascript-array-join-example
How do I join array elements in JavaScript?
To join JavaScript array elements in a string, you can use the array.join(separator) method. The array.join() method takes an array as input and a delimiter as a parameter and returns a string where all array elements are joined into a string ...
🌐
DEV Community
dev.to › gaelgthomas › array-to-string-without-commas-in-javascript-4mg6
Array to String Without Commas in JavaScript - DEV Community
September 18, 2022 - with parameter: your array will ... If you want to join your array with something different than commas, you can pass the separator of your choice....
🌐
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(,).