Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
26
rated 0 times [  27] [ 1]  / answers: 1 / hits: 167503  / 8 Years ago, tue, june 28, 2016, 12:00:00

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?



e.g.



This string ShouLD be ALL in title CASe


should become



This String Should Be All In Title Case

More From » lodash

 Answers
58

This can be done with a small modification of startCase:



_.startCase(_.toLower(str));




console.log(_.startCase(_.toLower(This string ShouLD be ALL in title CASe)));

<script src=https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.13.1/lodash.min.js></script>




[#61593] Monday, June 27, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bobbyallanh

Total Points: 693
Total Questions: 120
Total Answers: 101

Location: Bermuda
Member since Thu, Apr 20, 2023
1 Year ago
;