Simple Array
let simpleArray = ["Banana", "Orange", "Apple", "Mango"]
let commaSeperated = simpleArray.join(",");
console.log(commaSeperated);
Result
// 1,2,3,4
Array of Objects with a particular attributes as comma separated.
let arrayOfObjects = [
{
id : 1,
name : "Name A",
address : "Address A"
},
{
id : 2,
name : "Name B",
address : "Address B"
},
{
id : 3,
name : "Name C",
address : "Address C"
}]
let names = arrayOfObjects.map(x => x.name).join(", ");
console.log(names);
Result
// Name 1, Name 2, Name 3