How to convert javascript array to CSV?


It is very simple to convert an array to CSV.

Suppose you have a JS array of strings like this:

var vegetables= [‘onion’, ‘ladyfinger’, ‘peas’];
var str = vegetables.valueOf();

The valueOf() method will convert an array in javascript to a comma separated string.

Output:

onion, ladyfinger, peas

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: