jquery - Javascript remove commas from string -


this question has answer here:

i have below variable in javascript. want remove "comma" sign using jquery /javascript.

 var test = ",,2,4,,,3,,3,,,"  expected output: var test = "2,4,3,3" 

please advice

use replace() regex

var test = ",,2,4,,,3,,3,,,";    document.write(test.replace(/,+/g,',').replace(/^,|,$/g,''));

  1. replace(/,+/g,',') - remove multiple comma one.
  2. replace(/^,|,$/g,'') - remove comma @ starting , ending.

Comments

Popular posts from this blog

apache - setting document root in antoher partition on ubuntu -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -

Process 'command 'F:\android-sdk\build-tools\21.1.2\aapt.exe'' finished with non-zero exit value 1 -