Array JavaScript ke string CSV
var colors = ["red", "blue", "green"];
var colorsString = colors.join(","); //"red,blue,green"
Friendly Hawk
var colors = ["red", "blue", "green"];
var colorsString = colors.join(","); //"red,blue,green"
['tom', 'dick', 'harry'].join(', ').replace(/, ([^,]*)$/, ' and $1')
> "tom, dick and harry"
array.join("").toString()
const arr = [1, 2, 'a', '1a'];
const str = arr.toString();
console.log(str); //> "1,2,a,1a"
var cars = ["Volvo", "BMW", "Audi", "Chevrolet"];
console.log(cars.toString());
//Output: Volvo,BMW,Audi,Chevrolet
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"