How To Turn an Array Into a String Without Commas in JavaScript

How To Turn an Array Into a String Without Commas in JavaScript

If you need all array items converted into a single string without commas separating the elements, then you need to pass the empty string "" as an argument to the array .join() method.

Turn an Array into a String Without Commas

When you call JavaScript’s .join() (Array.prototype.join()) method with no argument, you’re actually using a comma.

The default behavior of .join() is to convert an array to a string with commas, so it’s the same as calling .join(",") explicitly.

When you call .join(",") you specify that you want a string literal "," to be the separator character, which will occur between each element. But it’s the same as .join() with no argument at all.

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 an [array](https://medium.com/javascript-in-plain-english/how-to-check-for-an-array-in-javascript-6ad20f7a0e21). The .split() method also takes a separator character.

By default, .split() without an argument doesn’t split a string at all, so in that sense it’s not a perfect mirror of .join(). But .split(",") and .join() will be equivalent.

Both .join() and .split() can be used with any string of any length as the separator, but you’ll often see a single comma used, like when creating a .csv (comma-separated values) file.

In the following code examples, we’ll take a string separated by commas, turn it into an array of individual characters, and then join the array together as a string without commas.

Image for post

View raw code as a GitHub Gist

programming javascript

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Learning JavaScript: Development Environments for JavaScript Programming

One of the nice things about learning JavaScript these days is that there is a plethora of choices for writing and running JavaScript code. In this article, I’m going to describe a few of these environments and show you the environment I’ll be using in this series of articles.

Learning JavaScript: Data Types and Variables

To paraphrase the title of an old computer science textbook, “Algorithms + Data = Programs.” The first step in learning a programming language such as JavaScript is to learn what types of data the language can work with. The second step is to learn how to store that data in variables. In this article I’ll discuss the different types of data you can work with in a JavaScript program and how to create and use variables to store and manipulate that data.

[ Professor JavaScript ]: Introduction

Professor JavaScript is a JavaScript online learning courses YouTube Channel. Students can learn how to develop codes with JavaScript from basic to advanced levels through the online courses in this YouTube channel.

Hire Dedicated JavaScript Developers -Hire JavaScript Developers

Hire dedicated JavaScript Developers who are proficient in AngularJS, ReactJS, NodeJS, & VueJS frameworks. Get flexible hiring models as per your business requirements.

Now Learn JavaScript Programming Language With Microsoft

Microsoft has released a new series of video tutorials on YouTube for novice programmers to get a hands-on renowned programming language — JavaScript.