when javascript and arrays were new to me. I needed to transform an object array into a string in JavaScript using commas to divide the strings. I considered how to turn an array into a string, either with or without commas.
I discovered how to convert an object array to a comma-separated string in two different ways using JavaScript after searching Google. The array property’s join() and toString() functions can be used for this. I’ve included both examples so you can use it and understand how it operates.
Looking at both examples will benefit your project.
Example 1:
<!DOCTYPE html>
<html>
<head>
<title>Javascript - Convert Array into Comma Separated String Example </title>
</head>
<body>
<script type="text/javascript">
var websites = ['holidaylandmark.com','wizbrand.com','motosahre.in'];
document.write(websites.toString());
</script>
</body>
</html>
OutPut:
holidaylandmark.com,wizbrand.com,motosahre.in
Example 2:
<!DOCTYPE html>
<html>
<head>
<title>Javascript - Convert Array into Comma Separated String Example</title>
</head>
<body>
<script type="text/javascript">
var websites = ['holidaylandmark.com','wizbrand.com','motosahre.in'];
document.write(websites.join('='));
</script>
</body>
</html>
OutPut:
holidaylandmark.com=wizbrand.com=motosahre.in