Javascript String titleize(splitter)

Description

Javascript String titleize(splitter)


String.prototype.titleize = function(splitter) {
  var words = this.split(splitter ? splitter : ' ')
  var array = []/*  www.  ja  v a 2  s .  co m*/
  for (var i=0; i<words.length; ++i) {
    array.push(words[i].charAt(0).toUpperCase() + words[i].toLowerCase().slice(1))
  }
  return array.join(' ')
}

String.prototype.toName = function() {
  return this.toLowerCase().replace(/\s/g, '_')
}



PreviousNext

Related