how to remove “,” from a string in javascript

后端 未结 6 485
我在风中等你
我在风中等你 2020-12-24 00:03

original string is \"a,d,k\" I want to remove all , and make it to \"adk\".

I tried code below but it doesn\'t work.

6条回答
  •  失恋的感觉
    2020-12-24 00:38

    If you need a number greater than 999,999.00 you will have a problem.
    These are only good for numbers less than 1 million, 1,000,000.
    They only remove 1 or 2 commas.

    Here the script that can remove up to 12 commas:

    function uncomma(x) {
      var string1 = x;
      for (y = 0; y < 12; y++) {
        string1 = string1.replace(/\,/g, '');
      }
      return string1;
    }
    

    Modify that for loop if you need bigger numbers.

提交回复
热议问题