How to add space between numbers with JavaScript?

Sometimes, we want to add space between numbers with JavaScript.

In this article, we’ll look at how to add space between numbers with JavaScript.

How to add space between numbers with JavaScript?

To add space between numbers with JavaScript, we use the number toLocaleString method.

For instance, we write

const num = 1234567890;
const result = num.toLocaleString("fr");

to call num.toLocaleString with "fr" to return a number in the Frenchlocale.

This will return '1 234 567 890'.

Conclusion

To add space between numbers with JavaScript, we use the number toLocaleString method.