Skip to content

Latest commit

 

History

History
23 lines (16 loc) · 640 Bytes

build-a-sentence-from-a-javascript-array.md

File metadata and controls

23 lines (16 loc) · 640 Bytes

Build a Sentence from a JavaScript Array

Have you ever wanted to take a JavaScript array of strings and turn them into a sentence? Here's how you do that.

const toLearn = [
  'object-oriented programming',
  'frontend engineering',
  'testing',
]

const sentence = new Intl.ListFormat().format(toLearn)
> "object-oriented programming, frontend engineering, and testing"

ListFormat takes options.

This has cross-browser support! The days of building a 'to sentence' function in JavaScript are over.