1 2 3
function numberWithCommas(x) { return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','); }
You can clone a snippet to your computer for local editing. Learn more.