Javascript String capitalize(capitalize_all_letters)

Description

Javascript String capitalize(capitalize_all_letters)



/**//  w w w  .  ja  v a 2 s . co  m
 * String, Javascript Extended Functions
 */

String.prototype.capitalize = function (capitalize_all_letters) {
 if(capitalize_all_letters)
  return this.split(' ').forEach(function(v,i,a){a[i] = v.capitalize()}).join(' ');
 return this.charAt(0).toUpperCase() + this.slice(1);
};



PreviousNext

Related