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: TThe 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

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

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.