How to use the toString() method In Javascript

In this method, we will use the toString() method o obtain the CSVs or the Comma Separated Values.

javascript




let array = ["geeks", "4", "geeks"];
let csv = array.toString();
console.log(csv);


Output

geeks,4,geeks



The toString() method converts an array into a String and returns the result. The returned string will separate the elements in the array with commas. 

Converting JavaScript Arrays into CSVs and Vice-Versa

Converting Arrays into CSVs: Given an array in JavaScript and the task is to obtain the CSVs or the Comma Separated Values from it. Now, JavaScript being a versatile language provides multiple ways to achieve the task.

Some of them are listed below.

Similar Reads

Method 1: Using the toString() method

In this method, we will use the toString() method o obtain the CSVs or the Comma Separated Values....

Method 2: Using valueof() Method

...

Method 3: Using the join() function

The valueOf() method returns the primitive value of an array. Again the returned string will separate the elements in the array with commas. There is no difference between toString() and valueOf(). Even if we try with different data types like numbers, strings, etc it would give the same result....

Method 4: Using the split() function

...

Contact Us