In this tutorial explained to convert array to comma separated string javascript. how we can convert array to string with commas or without commas.
I find out way to convert object array to comma separated string two way in javascript. using toString() and join() function of array property. we have exaplain examples for your help.
Let’s see both example and you can use examples.
Example 1:
convert array to string using toString() function
<script type="text/javascript">
var dataval = ["first","second","third"];
document.write(dataval.toString());
</script>
Output:
first,second,third
Example 2:
<script type="text/javascript">
var dataval = ["first","second","third"];
document.write(dataval.join('='));
</script>
Output:
first=second=third
Explanation of convert array to comma separated string javascript
we have an array called dataval containing various datavalue.
we use the toString() and join() function.This method join all elements of the array into single string, separated by the specified separator.
the separator we specify is ‘=’,which means each element in the resulting string will be separated by a comma followed a space.
I hope this tutorial help you..
Jasminkumar Borad
I'm a full-stack developer, enterpreneur and owner of webstuffsolution.com. I live in india and i like to write tutorial and tips that can help to other user. I like to share various programming language tips and solution. I believe in hardworking and consistency.