1function numberWithCommas(x) {
2 return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
3}
1function numberWithCommas(x) {
2 return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
3}
1//ES6 Way
2const numberWithCommas = (x) => {
3 return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
4}