Array to String Without Commas in JavaScript

In this article, you’ll discover how to convert an array to a string without commas. By no commas, I mean no separator between your array elements (words) or a separator different than a comma.

How to Convert Array to String Without Commas


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Gaël Thomas

In this article, you’ll discover how to convert an array to a string without commas. By no commas, I mean no separator between your array elements (words) or a separator different than a comma.

How to Convert Array to String Without Commas

In JavaScript, all arrays have a built-in method called join(). You can use it to convert an array to a string without commas. 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.

Concrete Example: Join Array to String

Without Commas

As mentioned in the above paragraph, you can use the join method to create a string without commas from your array.

This method works on an Array and takes up to one parameter:

  • no parameter: your array will be joined with commas (["hello", "world"].join())
  • with parameter: your array will be joined with the string provided as a parameter (["hello", "world"].join("-"))

Let me give you an example without commas:

const helloMagicWorldArray = ["Hello", "Magic", "World"]
const helloMagicWorldString = helloMagicWorldArray.join("")

console.log(helloMagicWorldString)
// Output: "HelloMagicWorld"

With Separator

I suppose you start the get the idea! If you want to join your array with something different than commas, you can pass the separator of your choice.

const helloMagicWorldArray = ["Hello", "Magic", "World"]

console.log(helloMagicWorldArray.join("/"))
// Output: "Hello/Magic/World"

console.log(helloMagicWorldArray.join(" - "))
// Output: "Hello - Magic - World"

If you want to go further, you can learn how to:

Thanks for reading. Let’s connect!

➡️ I help you grow into Web Development, and I share my journey as a Nomad Software Engineer. Join me on Twitter for more. 🚀🎒


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Gaël Thomas


Print Share Comment Cite Upload Translate Updates
APA

Gaël Thomas | Sciencx (2022-09-18T11:06:32+00:00) Array to String Without Commas in JavaScript. Retrieved from https://www.scien.cx/2022/09/18/array-to-string-without-commas-in-javascript/

MLA
" » Array to String Without Commas in JavaScript." Gaël Thomas | Sciencx - Sunday September 18, 2022, https://www.scien.cx/2022/09/18/array-to-string-without-commas-in-javascript/
HARVARD
Gaël Thomas | Sciencx Sunday September 18, 2022 » Array to String Without Commas in JavaScript., viewed ,<https://www.scien.cx/2022/09/18/array-to-string-without-commas-in-javascript/>
VANCOUVER
Gaël Thomas | Sciencx - » Array to String Without Commas in JavaScript. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/09/18/array-to-string-without-commas-in-javascript/
CHICAGO
" » Array to String Without Commas in JavaScript." Gaël Thomas | Sciencx - Accessed . https://www.scien.cx/2022/09/18/array-to-string-without-commas-in-javascript/
IEEE
" » Array to String Without Commas in JavaScript." Gaël Thomas | Sciencx [Online]. Available: https://www.scien.cx/2022/09/18/array-to-string-without-commas-in-javascript/. [Accessed: ]
rf:citation
» Array to String Without Commas in JavaScript | Gaël Thomas | Sciencx | https://www.scien.cx/2022/09/18/array-to-string-without-commas-in-javascript/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.