Javascript String capitalizeWords()

Description

Javascript String capitalizeWords()

String.prototype.capitalizeWords = function() {
 var words = this.split(/\s+/), 
  wordCount = words.length,/*w  w  w. j  av a 2s .  c o m*/
  i,
  newWords = [];
 
 for (i = 0; i < wordCount; i++) {
  newWords.push(words[i].capitalize());
 }
 
 return newWords.join(' '); 
};



PreviousNext

Related