Javascript String Prototype Capitalize Words

Description

Javascript String Prototype Capitalize Words


// This utility will capitalize the first letter of
// each word in a string

String.prototype.capitalize = function() {
  return this.replace(/\b[a-z]/g, function(matchChar){
    return matchChar.toLocaleUpperCase();
  });/*from   w w  w .jav a  2  s . c  om*/
}

console.log("alexei robert white".capitalize());



PreviousNext

Related