-1

I have a variable A as follows:

A = [[a],[b],[c],[d],.....]

I need to make this array to comma separated values as:

A = a,b,c,d,....

What I did is as follows:

A = A.replace("[", "");
A = A.replace("]", "");

But not working!!

Getting error as A.replace is not a function

user1989
  • 163
  • 7
  • Are you having array or string ? – intekhab Sep 03 '15 at 09:13
  • possible duplicate of [Easy way to turn Javascript array into comma-separated list?](http://stackoverflow.com/questions/201724/easy-way-to-turn-javascript-array-into-comma-separated-list) – Grundy Sep 03 '15 at 09:27
  • can you provide [jsfiddle](http://jsfiddle.net/), that can reproduce your problem? – Grundy Sep 03 '15 at 09:33

2 Answers2

1

I would suggest using underscore.js:

_.flatten(A).join(',')

EDIT: underscore in not actually needed (kudos @Grundy):

A.join(',')
Community
  • 1
  • 1
slomek
  • 4,873
  • 3
  • 17
  • 16
1

var A = [["a"],["b"],["c"],["d"]];
alert(A.toString()); // .join not even needed
mplungjan
  • 169,008
  • 28
  • 173
  • 236