Had the need to fill a string with '0' at the end.
var len = 64; var sb = parseInt(1023).toString(2); var sbl = sb.length; var sbFixedLenStart = ('0').repeat((len-sbl)?(len-sbl):0) + sb; var sbFixedLenEnd = sb + ('0').repeat((len-sbl)?(len-sbl):0); console.log(sbFixedLenStart); console.log(sbFixedLenEnd); /* output 0000000000000000000000000000000000000000000000000000001111111111 1111111111000000000000000000000000000000000000000000000000000000 */
@MaBe started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Had the need to fill a string with '0' at the end.