Skip to content

Instantly share code, notes, and snippets.

@AsaoluElijah
Last active October 1, 2020 11:50
Show Gist options
  • Save AsaoluElijah/ab32f958c1073e1cc1be258a9fc56a90 to your computer and use it in GitHub Desktop.
Save AsaoluElijah/ab32f958c1073e1cc1be258a9fc56a90 to your computer and use it in GitHub Desktop.
Add comma separator to thousands in JavaScript

Add comma separator to thousands - Javascript

const numberWithCommas = (x) => {
    return Number(x).toLocaleString();
}

Example

console.log(numberWithCommas(123456789)); // returns "123,456,789
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment