brandonscript brandonscript - 1 year ago 486
Javascript Question

Lodash title case (uppercase first letter of every word)

I'm looking through the lodash docs and other Stack Overflow questions - while there are several native JavaScript ways of accomplishing this task, is there a way I can convert a string to title case using purely lodash functions (or at least existing prototypal functions) so that I don't have to use a regular expression or define a new function?


This string ShouLD be ALL in title CASe

should become

This String Should Be All In Title Case

Answer Source

This can be done with a small modification of startCase:


var str = "This string ShouLD be ALL in title CASe";
str = _.startCase(_.toLower(str));
<script src=""></script>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download