javascript format numbers with commas
snippet in javascript

number with commas js

user6811

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

javascript format numbers with commas

user1056

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

how to format an integer with a comma in javascript

user8002

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