Author -  Sai gowtham

How to Convert Array to a String in JavaScript

In this tutorial, we are going to learn about converting an array to a string in JavaScript.

First way: Using join() method

The join() method converts the array of elements into a string separated by the commas.

Example:

const arr = [1,'a','b','c'];

console.log(arr.join());

// output --> "1,a,b,c"

We can also pass our own separator as an argument to the join() method.

In this below example, we passed - as a separator argument so that string is separated by a minus operator -.

const arr = [1,'a','b','c'];

console.log(arr.join('-'));

// output --> "1-a-b-c"

Second Way: Using toString() method

The toString() method also joins the array and returns the string where the array of elements is separated by the commas.

Example:

const arr = [1,'a','b','c'];

console.log(arr.toString());

// output --> "1,a,b,c"

Third way: Using an empty string

If we add an array with an empty string '' it converts the array to a string.

Example:

const arr = [1,'a','b','c'];

console.log(arr + '');

// output --> "1,a,b,c"

Css Tutorials & Demos

How rotate an image continuously in CSS

In this demo, we are going to learn about how to rotate an image continuously using the css animations.

How to create a Instagram login Page

In this demo, i will show you how to create a instagram login page using html and css.

How to create a pulse animation in CSS

In this demo, i will show you how to create a pulse animation using css.

Creating a snowfall animation using css and JavaScript

In this demo, i will show you how to create a snow fall animation using css and JavaScript.

Top Udemy Courses

JavaScript - The Complete Guide 2023 (Beginner + Advanced)
JavaScript - The Complete Guide 2023 (Beginner + Advanced)
116,648 students enrolled
52 hours of video content
$14.99 FROM UDEMY
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
631,582 students enrolled
49 hours of video content
$24.99 FROM UDEMY
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
203,937 students enrolled
31.5 hours of video content
$14.99 FROM UDEMY