Javascript examples for String Operation:String Character
Make first character uppercase of all words in JavaScript
<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>