How to remove comma from the string in javascript?

Today, We want to share with you remove comma from string javascript.In this post we will show you How to Remove Commas from Array in JavaScript, hear for remove first and last comma from string in javascript? we will give you demo and example for implement.In this post, we will learn about delete comma from number js with an example.

How to remove comma from string in jquery/javaScript with example ?

Sometimes, we require to remove comma, semicolon, colon etc from string in your jquery code At that time you can simply remove comma using js replace(). Jquery replace() through we can replace comma into empty string that way comma will be remove from jquery string.

remove text after a comma

var strDataVal = 'Welcome To Pakainfo,com, My Long Love live in Rajkot';
console.log("The original value="+strDataVal);
var expression = strDataVal.match(/([^,]*)(.*)/)[1];
var positionForComma = strDataVal.match(/([^,]*),(.*)/)[2].split(' ')[1]
var resData = expression + ', ' + positionForComma
console.log("Updated="+resData);

JavaScript Regex To Remove Commas From A String

function DeleteComma(MyString)
{

var objRegex = '/,/g';

//Replace Commas By Null....
return MyString.replace(objRegex,'');
}

Remove Last Comma from String in jQuery

Example 3: index.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Remove last comma from string jquery - www.pakainfo.com</title>
  <!--<script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>-->
  <script src="jquery-1.9.1.js" type="text/javascript"></script>
  <script type="text/javascript">
  $(function () {
  $('.finalCleanResults').click(function (event) {
  var resDataLatest = $.trim($('.txtValue').val());
  var lastChar = resDataLatest.slice(-1);
  if (lastChar == ',') {
  resDataLatest = resDataLatest.slice(0, -1);
  }
  $("#output").text(resDataLatest);
  });
  });
  </script>
</head>
<body>
  <div>
  <table>
  <tr>
   <td>
  <input type="text" class="txtValue" value="tamilrokers, bolly4u, khatrimaja, Okhatrimaja," />
  </td>
  <td>
  <button class="finalCleanResults">Delete</button>
  </td>
  </tr>
  <tr>
  <td>
  <div id="output" style="color:red;"></div>
  </td>
  </tr>
  </div>
</body>
</html>

index.html

<html lang="en">

<head>
  <title>Jquery remove comma from string - www.pakainfo.com</title>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
</head>
<body>

<script type="text/javascript">

    $(document).ready(function() {
      var finalCleanResults = "Welcome, Pakainfo. Nice City From Rajkot?";
      finalCleanResults = finalCleanResults.replace(/,/g, "");
      alert(finalCleanResults);
    });
</script>
</body>

</html>

I hope you get an idea about delete all comma from string javascript.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.