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

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

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