jQuery Data Type How to - Replace all commas in a string








Question

We would like to know how to replace all commas in a string.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
<!-- w w  w  . j  a va  2  s.  c  o m-->
var mystring = "this,is,a,test"
document.writeln(mystring.replace(/,/g , ":"));

</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: