Skip to content

JavaScript Array to string without commas | Conversion code

  • by

Use the join() method to join all the elements of an array into a single string without commas in JavaScript.

Array.join("");

Note: if no argument is specified a comma is used.

You can use also the built-in Array method toString to convert a JavaScript array into a string with commas.

Array.toString();

Note: The toString method can’t be used on an array of objects because it will return [object Object] instead of the actual values.

To convert an array of objects into a string, you need to use the JSON.stringify method:

JSON.stringify(ArrayObj);

Convert JavaScript Array to string without commas

A simple example code join accepts one string parameter which will serve as the separator for your string. Blank value(“”) is passed in as an argument while converting the array to a string value.

<!DOCTYPE html>
<html>
<head>

  <script>

    let arr = ["ABC", "Is", "Popular","Language"];
    let res  = arr.join("");

    console.log(res);
    console.log(typeof(res))

  </script>

</head>
</html>

Output:

JavaScript Array to string without commas

More Examples

[1, 2, 3].join(); // "1,2,3"
[1, 2, 3].join("+"); // "1+2+3"
[1, 2, 3].join(" "); // "1 2 3"

Do comment if you have any doubts or suggestions on this JS Array to String code.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading