String to capitalize Words - Node.js String

Node.js examples for String:Case

Description

String to capitalize Words

Demo Code


String.prototype.capitalizeWords = function() {
  var words = this.split(/\s+/), 
    wordCount = words.length,//from ww  w.ja  v a2  s. co  m
    i,
    newWords = [];
  
  for (i = 0; i < wordCount; i++) {
    newWords.push(words[i].capitalize());
  }
  
  return newWords.join(' ');  
};

Related Tutorials