Skip to content

Instantly share code, notes, and snippets.

@queviva
Created February 3, 2022 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save queviva/c737dba9f79203c0e00fe04a4e18f83d to your computer and use it in GitHub Desktop.
Save queviva/c737dba9f79203c0e00fe04a4e18f83d to your computer and use it in GitHub Desktop.
front pads number with zero
('00000' + n).slice(-3)
@queviva
Copy link
Author

queviva commented Feb 3, 2022

put as many zeros as necessary, and set the slice to negative-whatever

@queviva
Copy link
Author

queviva commented Feb 3, 2022

comparing lengths for the most common usage

('000'+n).slice(-3),
(''+n).padStart(3,'0')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment