thousands separator

    0

    2

    anastasiia-tilikina

    The code fragment replaces every three-digit number with a comma and every number not containing a comma with a dash.

    Shortcut: spitcomma

    function numberWithCommas(x) {
      return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
    }
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.