Sunday 25 December 2022

How to convert array into comma separated string in javascript

 Problem:

I have an array

a.value = [a,b,c,d,e,f]

How can I convert to comma seperated string like

a.value = "a,b,c,d,e,f"

Thanks for all help.



----------------------------------------------------------------------------------------------------------------


Solution:


The method array.toString() actually calls array.join() which result in a string concatenated by commas. ref

var array = ['a','b','c','d','e','f'];
document.write(array.toString()); // "a,b,c,d,e,f"


No comments:

Post a Comment