Computer >> Computer tutorials >  >> Programming >> Javascript

How to remove leading zeros from a number in JavaScript?


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 −

<!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