Advertisement
k98kurz

ucfirst and ucwords in JavaScript

Feb 15th, 2018
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. String.prototype.ucfirst = function()
  2. {
  3.     return this.charAt(0).toUpperCase() + this.substr(1).toLocaleLowerCase();
  4. }
  5.  
  6. String.prototype.ucwords = function()
  7. {
  8.     var arr = this.split(' ');
  9.     arr.forEach(function(e, i, a){ a[i] = e.ucfirst(); });
  10.     return arr.join(' ');
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement