Use the join method:

alert(testarray.join("%")); // 'a%b%c'

Here's a working example. Note that by passing the empty string to join you can get the concatenation of all elements of the array:

alert(testarray.join("")); // 'abc'

Side note: it's generally considered better practice to use an array literal instead of the Array constructor when creating an array:

var testarray = ["a", "b", "c"];
Answer from James Allardice on Stack Overflow
๐ŸŒ
Reddit
reddit.com โ€บ r/learnjavascript โ€บ remove comma from an array
r/learnjavascript on Reddit: Remove Comma from an Array
January 21, 2022 -

I created a div element and appended an array into it. However, when the array is printed, it shows the commas as well. Is there a way to remove the commas when printing the array? (Please ignore the really weird choice of words, I just placed random words in the array to test something).

Input Output
How to Convert Array to String without Commas in JS? May 10, 2023
r/JavaScriptTips
3y ago
Comma operator in JavaScript Oct 26, 2025
r/learnjavascript
8mo ago
What's with the trailing commas? Aug 24, 2017
r/javascript
8y ago
More results from reddit.com
Discussions

javascript - How do I remove commas from an array of strings - Stack Overflow
I have a list of arrays as so: 0: "1 Trenchard Road, , , , Saltford, Bristol, Avon" 1: "10 Trenchard Road, , , , Saltford, Bristol, Avon" 2: "11 Trenchard Road, , , , Saltford, Bristol, Avon" 3: "12 More on stackoverflow.com
๐ŸŒ stackoverflow.com
February 2, 2016
node.js - Remove comma from value box in array - Stack Overflow
Nodejs : How to Remove comma in value parameter in array More on stackoverflow.com
๐ŸŒ stackoverflow.com
Remove comma from javascript array - Stack Overflow
Hi all I am framing a url with Query string in javascript as follows every thing works fine but a comm is coming in between the query string so can some one help me More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to remove comma and "" from JavaScript Array? - Stack Overflow
I have an array which I need to remove the commas and "" surrounding each item in the array. I used .join('') and also toString(). More on stackoverflow.com
๐ŸŒ stackoverflow.com
June 24, 2016
๐ŸŒ
Quora
quora.com โ€บ How-do-I-remove-commas-while-displaying-an-array-in-JavaScript
How to remove commas while displaying an array in JavaScript - Quora
Answer (1 of 5): * By default the [code ].toString()[/code] of an [code ]Array[/code] will use comma as its delimiter. To display them next to each other * Use join Method * The [code ]join()[/code] method joins all elements of an array (or an array-like object) into a string and returns this...
๐ŸŒ
EncodedNA
encodedna.com โ€บ javascript โ€บ how-to-remove-commas-from-array-in-javascript.htm
How to Remove Commas from Array in JavaScript
You can use the join() method in JavaScript to remove commas from an array. The comma delimiter in an array works as the separator.
๐ŸŒ
javaspring
javaspring.net โ€บ blog โ€บ replace-string-in-javascript-array
How to Remove Commas from Strings in a JavaScript Array: A Step-by-Step Guide โ€” javaspring.net
Ignoring non-string elements: If your array has non-strings, replace() will throw an error. Use typeof item === 'string' to check first. Removing commas from strings in a JavaScript array is straightforward with the right tools.
๐ŸŒ
LinkedIn
linkedin.com โ€บ pulse โ€บ how-remove-comma-from-string-javascript-vkaif
How to remove comma from string in JavaScript
March 19, 2024 - Then, we use the join method to join the array elements back into a string without any delimiter. Method 3: Using Regular Expression and Global Flag ยท You can also utilize a regular expression with the global flag to match all occurrences of commas in the string and remove them.
๐ŸŒ
Medium
medium.com โ€บ @gaelgthomas โ€บ array-to-string-without-commas-in-javascript-d4e6ebcbf3e2
Array to String Without Commas in JavaScript | by Gaรซl Thomas | Medium
September 18, 2022 - You can call the join method with an empty string as a parameter (join("")). The method will return a string with all the array elements concatenated. As mentioned in the above paragraph, you can use the join method to create a string without ...
๐ŸŒ
Java2Blog
java2blog.com โ€บ home โ€บ core java โ€บ remove comma from string in javascript
Remove Comma from String in JavaScript - Java2Blog
May 24, 2022 - Then joined the array elements with empty String using join() method. Thatโ€™s all about how to remove comma from string in Javascript.
Find elsewhere
๐ŸŒ
xjavascript
xjavascript.com โ€บ blog โ€บ removing-commas-from-javascript-array
How to Remove Commas from a JavaScript Array and Replace with Custom Characters (e.g., %, %$) โ€” xjavascript.com
Working with arrays is a fundamental part of JavaScript development, whether youโ€™re building web apps, processing data, or formatting output. A common scenario arises when converting arrays to strings: by default, JavaScript joins array elements with commas (e.g., `[1, 2, 3]` becomes `"1,2,3"`). While commas are useful in many cases, there are times you need to replace them with custom charactersโ€”such as `%`, `%$`, hyphens, or even spaces.
Top answer
1 of 4
2

You can use JavaScript Array#map with RegEx to remove extra commas.

arr.map(e => e.replace(/(,\s*)+/, ','));

ES5 Equivalent:

arr.map(function (e) {
    return e.replace(/(,\s*)+/, ',');
});

RegEx Demo

The regex (,\s*)+ will search for one or more commas separated by any number of spaces between them.

Show code snippet

var arr = ["1 Trenchard Road, , , , Saltford, Bristol, Avon", "10 Trenchard Road, , , , Saltford, Bristol, Avon", "11 Trenchard Road, , , , Saltford, Bristol, Avon", "12 Trenchard Road, , , , Saltford, Bristol, Avon"];

arr = arr.map(e => e.replace(/(,\s*)+/, ', '));
console.log(arr);

document.getElementById('result').innerHTML = JSON.stringify(arr, 0, 4);
<pre id="result"></pre>
Run code snippetEdit code snippet Hide Results Copy to answer Expand

2 of 4
1

You can split by coma, filter blanks and join.

var str = "1 Trenchard Road, , , , Saltford, Bristol, Avon";
var result = str.split(',').filter(x => x.trim()).join()
console.log(result); // 1 Trenchard Road, Saltford, Bristol, Avon

Notice: used ES6 arrow function (=>) you can replace it with classical function if it does not work in your environment.

Full example with map function:

let arr = [
    '1 Trenchard Road, , , , Saltford, Bristol, Avon',
    '10 Trenchard Road, , , , Saltford, Bristol, Avon',
    '11 Trenchard Road, , , , Saltford, Bristol, Avon',
    '12 Trenchard Road, , , , Saltford, Bristol, Avon'
];

let result = arr.map(i => i.split(',').filter(x => x.trim()).join());

ES5 Equivalent:

var result = arr.map(function(i) {
    return i.split(',').filter(function(x) {
        return x.trim();
    }).join();
});
๐ŸŒ
DEV Community
dev.to โ€บ raj_vue โ€บ how-to-remove-trailing-commas-from-the-last-element-of-an-array-using-javascript-4jme
How to remove trailing commas from the last element of an array using JavaScript? - DEV Community
December 11, 2022 - Find the last element from an array using length. array.length-1; Replace comma using replace method and filter new value array[last_index].replace(',', '');
๐ŸŒ
Medium
frontendinterviewquestions.medium.com โ€บ how-to-remove-comma-from-string-in-javascript-0b5cc90fd65f
How to remove comma from string in JavaScript | by Pravin M | Medium
April 15, 2024 - Another approach to remove commas from a string is by splitting the string into an array based on the comma delimiter and then joining the array elements back into a string without commas.
๐ŸŒ
Bobby Hadz
bobbyhadz.com โ€บ blog โ€บ javascript-remove-all-commas-from-string
Remove/Replace all Commas from a String in JavaScript | bobbyhadz
The function takes the string as a parameter and removes all occurrences of a comma from the string. Alternatively, you can use the String.split() method. ... Use the String.split() method to split the string on each comma. Use the Array.join() method to join the array into a string without a delimiter.
๐ŸŒ
JavaScript in Plain English
javascript.plainenglish.io โ€บ how-to-turn-an-array-into-a-string-without-commas-in-javascript-241598bb054b
How to Turn an Array Into a String Without Commas in JavaScript | by Dr. Derek Austin ๐Ÿฅณ | JavaScript in Plain English
January 6, 2023 - If you call .join("") with the empty string "" instead, then all of the elements will be joined together without commas. We can demonstrate this behavior with the .split() method (String.prototype.split()), which splits up a string and returns ...
๐ŸŒ
Reddit
reddit.com โ€บ r/learnjavascript โ€บ remove comma from number in array.
r/learnjavascript on Reddit: Remove comma from number in array.
March 30, 2022 -

Hi all, I'm trying to remove commas from my numbers that are in an array :

I know the method '.toFixed(2)' but I'm having trouble applying it in a .map

This is what I did:

And this is what I get :

Unfortunately I added the two values โ€‹โ€‹so I don't get an array anymore.

What would be the right way to find an array like I had but without a comma?
How do I merge them into my array? ๐Ÿ™‚