Добавить ведущие нули к номеру JavaScript
const number = 5;
console.log(number.toString().padStart(2, '0')); // expected output: "05"
Smiling Skipper
const number = 5;
console.log(number.toString().padStart(2, '0')); // expected output: "05"
('0' + 11).slice(-2) // '11'
('0' + 4).slice(-2) // '04'
const str1 = '5';
console.log(str1.padStart(2, '0')); // expected output: "05"
var MyDate = new Date();
var MyDateString;
MyDate.setDate(MyDate.getDate() + 20);
MyDateString = ('0' + MyDate.getDate()).slice(-2) + '/'
+ ('0' + (MyDate.getMonth()+1)).slice(-2) + '/'
+ MyDate.getFullYear();