Make first character uppercase of all words in JavaScript - Javascript String Operation

Javascript examples for String Operation:String Character

Description

Make first character uppercase of all words in JavaScript

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.4.4.min.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){/*from  ww  w .  ja  v a  2  s  .  c o m*/
var example = "FoO_BAR bAz this is a test";
function foo(str) {
    return str.toLowerCase().replace(/(?:_| |\b)(\w)/g, function(str, p1) { return p1.toUpperCase()});
}
console.log( foo(example) );
    });

      </script> 
 </head> 
 <body>  
 </body>
</html>

Related Tutorials