convert '1' to '0001' in JavaScript
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/2686855/is-there-a-javascript-function-that-can-pad-a-string-to-get-to-a-determined-lengt">Is there a JavaScript function that can pad a string to get to a determined length?</a>  </p>
</blockquote>



<p>How can I convert convert '1' to '0001' in JavaScript without using any 3rd party libraries. I have done this in php using spritf: <code>$time = sprintf('%04.0f',$time_arr[$i]);</code></p>
