How to Format numbers with commas in Javascript

This post shows you how to print a number with commas as thousands separators in JavaScript.

For example:

1234 //1,234
1234567890 //1,234,567,890

You can use regular expression

function formatNumber(value) {
    return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");

This is the best way to help you print an integer with commas as thousands separators.