Categories
JavaScript Answers

How to remove leading zeros from a number in JavaScript?

Spread the love

Sometimes, we want to remove leading zeros from a number in JavaScript.

In this article, we’ll look at how to remove leading zeros from a number in JavaScript.

How to remove leading zeros from a number in JavaScript?

To remove leading zeros from a number in JavaScript, we can use the Number function.

For instance, we write

const numString = "065";
number = Number(numString);
console.log(number);

to call Number with numString to return the number converted from numString.

The leading zeroes in the string will be dropped.

Conclusion

To remove leading zeros from a number in JavaScript, we can use the Number function.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *