Is there a simple way to convert a string to title case? E.g. john smith becomes John Smith. I\'m not looking for something complicated like John R
john smith
John Smith
Here's my version, IMO it's easy to understand and elegant too.
var str = "foo bar baz" console.log( str.split(' ') .map(w => w[0].toUpperCase() + w.substr(1).toLowerCase()) .join(' ') ) // returns "Foo Bar Baz"