format number with commas js
snippet in javascript

number with commas js

user3684

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

javascript format numbers with commas

user2800

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

format number with commas js

user6774

foramtNumber = (num,div=",")=>{
  return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, div);

}

javascript friendly number format with commas

user8342

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

how to format an integer with a comma in javascript

user7297

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