Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Array to Sentence

How can I turn an array, such as ["Susy", "John", "Mary"] to "Susy, John, and Mary" in Javascript? I can't get Ruby's to_sentence method out of my head.

like image 726
Corey Avatar asked Feb 08 '13 00:02

Corey


1 Answers

Using newest JavaScript (Chrome 72+):

new Intl.ListFormat().format(["Susy", "John", "Mary"]);

which will result in:

"Susy, John, and Mary"
like image 111
Przemek Avatar answered Oct 12 '22 15:10

Przemek