You've successfully subscribed to Nicholas Workshop
Great! Next, complete checkout for full access to Nicholas Workshop
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info is updated.
Billing info update failed.

Capitalizing Words in Javascript

Nicholas Wong
Nicholas Wong

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();  
  });  
}  
Unsorted

Nicholas Wong

Fullstack software engineer with strong background in computer science and extensive experience in software engineering and architecture. Studied in NYU, worked in Yahoo, Rakuten and Manulife.