Sometimes, we want to add commas or spaces to group every three digits with JavaScript.
In this article, we’ll look at how to add commas or spaces to group every three digits with JavaScript.
How to add commas or spaces to group every three digits with JavaScript?
To add commas or spaces to group every three digits with JavaScript, we use the toLocaleString
method.
For instance, we write
console.log(Number(1234567890.12).toLocaleString());
to call toLocaleString
on the number to return a string with the thousands separators included.
Conclusion
To add commas or spaces to group every three digits with JavaScript, we use the toLocaleString
method.