JavaScript Snippet: Add Commas to Number By Regular-Expression

Posted at

16718 -> 16,718


function addCommas(t) {
return String(t).replace(/(\\d)(?=(\\d{3})+$)/g, "$1,")
}