Sorry for this inconveniently simple question, but I'm still relatively new to javascript.
I have an array of names, something like
var myArray = ['Hill M','Zhang F','Dong L', 'Wilkinson JS', 'Harris N'];
I would like to return a string with names separated by commas, but with a "and" between the last two names, i.e.
'Hill M, Zhang F, Dong L, Wilkinson JS and Harris N'
What is the most efficient way to do this in javascript?
How about if I need to rearrange the names and initials, i.e. to return
'M Hill, F Zhang, L Dong, JS Wilkinson and N Harris'
source
share