Posted By


edektor on 01/10/10

Tagged


Statistics


Viewed 293 times
Favorited by 0 user(s)

String.prototype.pad


/ Published in: JavaScript
Save to your folder(s)

pads a string "2".pad(2, "0"); //02


Copy this code and paste it in your HTML
  1. String.prototype.pad = function(l, s){
  2. return (l -= this.length) > 0
  3. ? (s = new Array(Math.ceil(l / s.length) + 1).join(s)).substr(0, s.length) + this + s.substr(0, l - s.length)
  4. : this;
  5. };

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.