By 05/02/2014 4 Comments

How to Convert a JavaScript Array into the Comma Seperated Value (CSV) format in Javascript

What is CSV ?

  • It stands for comma separated values
  • These are different multiple values with comma separation (e.g php, javascript, asp, facebook etc)
  • It is also called CSV file, that means that file’s extension is .csv and it contains comma separated values or data

valueOf()

  • This method is used to convert a javascript array into the CSV format
  • this function associated with an array object

Following code snippet Convert a JavaScript Array into the Comma Seperated Value (CSV) format.

 

<script>

var arr = ['abc', 'bcd', 'cde', 'def']; // initialize an array contains string values

var str = arr.valueOf(); // valueOf() method called by an array arr, assign to str variable

document.write(str); // display output

</script>

You can also use the pipe (|) instead of commas, For this you have to use the join() method.

<script>

var arr = ['abc', 'bcd', 'cde', 'def'];

var str = arr.join("|"); // join strings between pipe (|) symbol

document.write(str);

</script>






Posted in: JavaScript

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .