I've got an array of strings that I need to display as a comma-separated list, with "and" added before the last element. Here's what I have:
const fruits = ["Banana", "Orange", "Apple", "Mango"];
const energy = fruits.join(', ').replace(/,(?=[^,]*$)/,' and');
This code will output:
'Banana, Orange, Apple and Mango'
Is there any way to modify this so it adds "and" just before the last word in the list?