How to remove leading zeros from a number in JavaScript?

JavascriptWeb DevelopmentFront End Technology

Use parseInt() to remove leading zeros from a number in JavaScript.

Example

You can try to run the following code to run how to remove leading zeros −

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <script>
         var num1 = parseInt("025", 10);
         document.write(num1);

         var num2 = parseInt("040", 10);
         document.write("<br>"+num2);

         var num3 = parseInt("098", 10);
         document.write("<br>"+num3);
      </script>
   </body>
</html>

Output

25
40
98
raja
Published on 03-Feb-2018 12:54:14
Advertisements