Skip to content

Instantly share code, notes, and snippets.

View Utshab500's full-sized avatar
🏠
Working from home

Utshab Saha Utshab500

🏠
Working from home
View GitHub Profile
@endel
endel / number-pad-zero.js
Last active August 1, 2023 11:54
Simplest way for leading zero padding in JavaScript
Number.prototype.pad = function(size) {
var s = String(this);
while (s.length < (size || 2)) {s = "0" + s;}
return s;
}
(1).pad(3) // => "001"
(10).pad(3) // => "010"
(100).pad(3) // => "100"