Created: 2022-10-23
toString() always uses a comma.const dogNames = ['Rocket','Flash','Bella','Slugger'];
dogNames.toString(); // Rocket,Flash,Bella,Slugger
join() methodconst elements = ['Fire', 'Air', 'Water'];
console.log(elements.join('-'));
// expected output: "Fire-Air-Water"
To do this, we can use the split() method.
const data = 'Manchester,London,Liverpool,Birmingham,Leeds,Carlisle';
const cities = data.split(',');
// ['Manchester', 'London', 'Liverpool', 'Birmingham', 'Leeds', 'Carlisle']