function numberWithCommas(x) { return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','); }
function numberWithCommas(x) { return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); }
//ES6 Way const numberWithCommas = (x) => { return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','); }
function formatNumberWithCommas(x) { return x.toString().replace(/B(?=(d{3})+(?!d))/g, ","); }
x.toString().toLocaleString(); // x must be a number