Javascript 左侧自动补0
需求‘1’ -> ‘0001’方法1function prefix(num, val) { return val.padStart(num, '0');}prefix(4, '1') 方法2function prefix(num, val) { return (new Array(num + 1).join('0') + val).slice(-num);}prefix(4, '1')
原创
2020-05-21 19:00:02 ·
3290 阅读 ·
1 评论