In this tutorial explain of remove comma from string in jquery. we require to remove comma,semicolon,colon etc from string in jquery code. you can easily remove comma using js replace(). Jquery replace() use we can easily replace comma into empty string that way comma will be remove from jquery string.
In this article example you can see how it works.you can also delete semicolon,colon etc. So let’s try below example and see.
Example:
$(document).ready(function(){
var str = "Hi, Jasminkumar. How are you";
str = str.replace(/,/g, "");
console.log(str);
});
Output:
Hi Jasminkumar. How are you
Explanation:
This replace() function takes two arguments. The first is a regular expression, /,/g, where /,/ matches commas and g (global) ensures that it finds all occurrences, not just the first one. The second argument is an empty string (“”), meaning each comma found will be replaced with nothing, effectively removing all comma.
Remove Comma from string using split() and join() method
Another method to remove commas is to split the string by commas and then join it back without any seperator.
Example:
$(document).ready(function(){
var str = "Hi, Jasminkumar. How are you";
str = str.split(",").join("");
console.log(str);
});
I hope this tutorial help you.