Categories
JavaScript Answers

How to join an array by a comma and a space with JavaScript?

Spread the love

Sometimes, we want to join an array by a comma and a space with JavaScript.

In this article, we’ll look at how to join an array by a comma and a space with JavaScript.

How to join an array by a comma and a space with JavaScript?

To join an array by a comma and a space with JavaScript, we can use the array join method.

For instance, we write

const myArray = [
  "css",
  "html",
  "xhtml",
  "html5",
  "css3",
  "javascript",
  "jquery",
  "lesscss",
  "arrays",
  "wordpress",
  "facebook",
  "fbml",
  "table",
  ".htaccess",
  "php",
  "c",
  ".net",
  "c#",
  "java",
];
const myString = myArray.join(", ");

to call myArray.join with ', ' to combine each element in myArray into a string separated by a comma and a space.

The combined string is returned.

Conclusion

To join an array by a comma and a space with JavaScript, we can use the array join method.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.