Dołącz ostatni element JavaScript tablicy o innej wartości
['tom', 'dick', 'harry'].join(', ').replace(/, ([^,]*)$/, ' and $1')
> "tom, dick and harry"
Enchanting Eagle
['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 myNewString = myArray.join(',');
myNewString;
<array>.join(<splitting character(s)>);