Array::slice() Selects a part of an array, and returns the new array.
Array::join() Joins all elements of an array into a string
String::concat() Concatenates two or more strings.
var myArray = ['Hill M','Zhang F','Dong L', 'Wilkinson JS', 'Harris N'];
console.log(myArray.slice(0, myArray.length - 1).join(', ').concat(
' and ' + myArray[myArray.length - 1]));
//Hill M, Zhang F, Dong L, Wilkinson JS and Harris N
To change their order:
var myArray = ['Hill M','Zhang F','Dong L', 'Wilkinson JS', 'Harris N'];
for(var i = 0; i < myArray.length; i++)
myArray[i] = myArray[i].replace(/^(\S+)\s+(.+)$/, '$2 $1');
console.log(myArray.slice(0, myArray.length - 1).join(', ').concat(
' and ' + myArray[myArray.length - 1]));
//M Hill, F Zhang, L Dong, JS Wilkinson and N Harris
In case you are wondering about str.replace(/^(\S+)\s+(.+)$/, '$2 $1');
/^(\S+)\s+(.+)$/
is regular expression that matches a string that:
^ #starts with
\S+ #one or more non whitespace characters, followed by
\s+ #one or more whitespace characters, followed by
.+ #one or more characters
$1
and $2
in the replacement string stands for 1st and 2nd groups (subpatterns enclosed in parentheses) from the regex.