javascript join array with comma 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: .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 4: can you do a join() in js without the commas

arr.join("")

Example 5: javascript implode function

Javascript implode explode functions