I am trying to create a string with where i want to have the following
for and array ['john','harry', 'darren']
i expect below
e.g john harry and daren
is it even a valid case for internationalisation or am i better off just programming do this?
What you are looking for is Intl.ListFormat:
const names = ['john','harry', 'darren'];
const formatter = new Intl.ListFormat('en', { style: 'long', type: 'conjunction' });
console.log(formatter.format(names)); // prints john, harry, and darren
If you want to use the default locale, replace 'en'
with undefined
.