javascript friendly number format with commas
snippet in javascript

number with commas js

user6187

function numberWithCommas(x) {
  return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}

javascript friendly number format with commas

user7632

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

how to format an integer with a comma in javascript

user3853

x.toString().toLocaleString(); // x must be a number