function format(num) { var reg = /d{1,3}(?=(d{3})+$)/g; return (num + '').replace(reg, '$&,'); } console.log(format(123456789));//123,456,789
function format(num) { var reg = /d{1,3}(?=(d{3})+$)/g; return (num + '').replace(reg, '$&,'); } console.log(format(123456789));//123,456,789