How to uppercase every word in JavaScript

Strings
Last updated Dec 16, 2017
let string = "code to go is AWESOME";
const pattern = /([^\W_]+[^\s]*) */g;

string.replace(pattern, word => {
  const first = word.charAt(0).toUpperCase();
  const rest = word.substr(1).toLowerCase();
  return first + rest;
});
Code To Go Is Awesome