Join all elements of an array and create a human-readable string
npm install array-to-sentence


Join all elements of an array and create a human-readable string
``javascript`
arrayToSentence(['foo', 'bar', 'baz', 'qux']); //=> 'foo, bar, baz and qux'
#### npm
``
npm install array-to-sentence
`js`
import arrayToSentence from 'array-to-sentence';
array: Array Object
options: string
Return:
It joins all elements of an array, and returns a string in the form A, B, ... and X.
`javascript
arrayToSentence(['one', 'two', 3]); //=> 'one, two and 3'
arrayToSentence(['one', 'two']); //=> 'one and two'
arrayToSentence(['one']); //=> 'one'
arrayToSentence([]); //=> ''
`
Type: string ', '
Default:
Set the separator string of each word.
Type: string ' and '
Default:
Set the separator string before the last word.
`javascript
arrayToSentence(['A', 'B', 'C'], {
separator: '-',
lastSeparator: '-'
}); //=> 'A-B-C'
arrayToSentence(['Earth', 'Wind', 'Fire'], {
lastSeparator: ' & '
}); //=> 'Earth, Wind & Fire'
`
I used .toSentence()` method of underscore.string as API design reference. Thanks, Esa-Matti Suuronen and the contributors.
ISC License © 2018 Shinnosuke Watanabe