How to title case a sentence in JavaScript?

To title case a sentence in JavaScript, do this: sentence.split(" ").map(w => w.charAt(0).toUpperCase() + w.slice(1)).join(" ").

Here's how you do it:

const sentence = 'The quick brown fox jumped over the lazy dog';

const titleCased = string
  .split(' ')
  .map(w => w.charAt(0).toUpperCase() + w.slice(1))
  .join(' ');

// The Quick Brown Fox Jumped Over The Lazy Dog
console.log(titleCased);