javascript array to string with commas code example
Example 1: javascript array to comma separated string
var colors = ["red", "blue", "green"];
var colorsCSV = colors.join(","); //"red,blue,green"
Example 2: javascript array to csv string
var colors = ["red", "blue", "green"];
var colorsString = colors.join(","); //"red,blue,green"
Example 3: javascript array to string without commas
arr.join("")
Example 4: .join in javascript
const elements = ['Sun', 'Earth', 'Moon'];
console.log(elements.join());
// output: "Sun,Earth,Moon"
console.log(elements.join(''));
// output: "SunEarthMoon"
console.log(elements.join('-'));
// output: "Sun-Earth-Moon"
Example 5: javascript array to string without commas
[1, 2, 3].join(""); // 123
Example 6: js array join
['h', 'e', 'y'].join('')
// hey