How to format numbers with commas with JavaScript?

Sometimes, we want to format numbers with commas with JavaScript.

In this article, we’ll look at how to format numbers with commas with JavaScript.

How to format numbers with commas with JavaScript?

To format numbers with commas with JavaScript, we can use the toLocaleString method.

For instance, we write:

const no = 3456;
const noStr = no.toLocaleString();
console.log(noStr)

to call toLocaleString to return a number string with digit groups separated by commas.

Therefore, noStr is '3,456'.

Conclusion

To format numbers with commas with JavaScript, we can use the toLocaleString method.