Capitalizing Words in Javascript

Capitalizing Words in Javascript

This is a very old draft stuck at the bottom of my draft list. lol

var str = "hello world";  
str = str.toLowerCase().replace(/b[a-z]/g, function(letter) {  
  return letter.toUpperCase();  
});  
alert(str); // displays "Hello World"  

Making it as a function, we can do this.

function capitalize(str) {  
  return str.toLowerCase().replace(/b[a-z]/g, function(letter) {  
    return letter.toUpperCase();  
  });  
}