Javascript examples for String Operation:String Case
Uppercase first letter of a string variable
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=( function() {/*from w w w.j a v a2 s . c om*/ String.prototype.ucwords = function() { return this.toLowerCase().replace(/\b[a-z]/g, function(letter) { return letter.toUpperCase(); }); } console.log("hello world".ucwords()); console.log("this is a test".ucwords()); }); </script> </head> <body> </body> </html>