try

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

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'], '-') );

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
🌐
TutorialsPoint
tutorialspoint.com › typescript › typescript_array_join.htm
TypeScript - Array join()
join() method joins all the elements of an array into a string. separator − Specifies a string to separate each element of the array. If omitted, the array elements are separated with a comma.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › join
Array.prototype.join() - JavaScript | MDN
Because the string returned by Array.prototype.toString (which is the same as calling join()) does not have delimiters, nested arrays look like they are flattened. You can only control the separator of the first level, while deeper levels always use the default comma.
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
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
Show json array field as comma separated values
I have a JSON field which stored days of the week. I want to show those in my list but it’s displaying them like this: ["Mon","Tue","Wed","Thu","Fri"] I’m sure it must be easy to change this but cannot find how. I want to have this: Mon,Tue,Wed,Thu,Fri Can anyone assist me please? More on community.wappler.io
🌐 community.wappler.io
0
July 1, 2023
🌐
SPGuides
spguides.com › typescript-array-to-string-with-separator
How to Convert Typescript Array to String With Separator?
July 21, 2025 - Learn how to convert a TypeScript array to a string with a custom separator. Step-by-step guide with examples to join array elements efficiently.
🌐
Reddit
reddit.com › r/javascripttips › how do i convert an array to a string with commas in javascript
How do I convert an array to a string with commas in ...
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

🌐
GeeksforGeeks
geeksforgeeks.org › typescript › typescript-array-join-method
TypeScript Array join() Method - GeeksforGeeks
July 12, 2024 - The Array.join() method in TypeScript is a built-in function used to join all the elements of an array into a single string. This method is particularly useful when you need to concatenate array elements with a specific separator.
🌐
W3Schools
w3schools.com › jsref › jsref_join.asp
W3Schools.com
The join() method returns an array as a string. The join() method does not change the original array. Any separator can be specified.
Find elsewhere
🌐
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....
🌐
TutorialsPoint
tutorialspoint.com › home › typescript › typescript string split
TypeScript String Split
December 18, 2016 - TypeScript - null vs. undefined ... This method splits a String object into an array of strings by separating the string into substrings. ... separator − Specifies the character to use for separating the string.
🌐
Altcademy
altcademy.com › blog › how-to-convert-array-to-string-in-javascript
How to convert array to string in JavaScript
August 29, 2023 - You may be asking, "What is the difference between toString() and join()?" The primary difference is that toString() does not allow you to specify a custom separator. toString() will always separate array elements with a comma, while join() allows for custom separators. What happens when we have an array within an array, also known as a nested array? Can we convert that to a string too?
🌐
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(,).
🌐
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
🌐
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 function uses the toString() method to convert the array into a string, with the elements separated by commas by default.
🌐
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 - When you want just the comma character (,) to appear as the separator between items in the list, use .join(",") to convert the array to a string.
🌐
TutorialsPoint
tutorialspoint.com › How-to-turn-JavaScript-array-into-the-comma-separated-list
How to turn JavaScript array into the comma-separated list?
November 25, 2022 - The join() method joins all the elements of an array and forms a string and returns it later by separating every element with the specified separator passed to the method in form of a string.
🌐
Wappler Community
community.wappler.io › wappler general › need help
Show json array field as comma separated values - Need Help - Wappler Community
July 1, 2023 - I have a JSON field which stored days of the week. I want to show those in my list but it’s displaying them like this: ["Mon","Tue","Wed","Thu","Fri"] I’m sure it must be easy to change this but cannot find how. I want to have this: Mon,Tue,Wed,Thu,Fri Can anyone assist me please?
🌐
ServiceNow Community
servicenow.com › community › developer-forum › convert-array-string-to-comma-separated-string › m-p › 2606171
Convert Array String to Comma Separated String - ServiceNow Community
July 6, 2023 - (function execute(inputs, outputs) { var mrvs; var itemID = inputs.record_sysid; var ritmGR = new GlideRecord('sc_req_item'); if (ritmGR.get(itemID)) { mrvs = ritmGR.variables[inputs.variable_set_name]; } var mrvSort = JSON.parse(mrvs); var sortedArray = mrvSort.sort(function(a, b){ var x = a[inputs.variable_to_sort]; var y = b[inputs.variable_to_sort]; return x < y ? -1 : x > y ? 1 : 0; }); outputs.sorted_mrv_array = JSON.stringify(sortedArray); })(inputs, outputs);