jquery remove last comma from string Example

Today, We want to share with you jquery remove last comma from string.
In this post we will show you JavaScript remove last comma, hear for remove last comma from string java-script we will give you demo and example for implement.
In this post, we will learn about Remove Last Comma from String in jQuery with an example.

jquery remove last comma from string

There are the Following The simple About jquery remove last comma from string Full Information With Example and source code.

As I will cover this Post with live Working example to develop Remove last comma using jQuery, so the some major files and Directory structures for this example is following below.

  • index.html

JavaScript Remove last comma if Your last character is simple comma. First of all we have to check all the string as well as the last character in given your all the string is comma or not. and then check If last character is comma then I special remove the last your comma character.

Remove last comma using jQuery Example

index.html

This is where I will make a simple HTML form and PHP server side source code for our web application. To make the forms simply all souce code copy and write it into your any text editor Like Notepad++, then save file it as index.html.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>jquery remove last comma from string</title>
  <script src="jquery-1.9.1.js" type="text/javascript"></script>
  <script type="text/javascript">
  $(function () {
  $('.removeBtn').click(function (event) {
  var liveVal = $.trim($('.myval').val());
  var lastChar = liveVal.slice(-1);
  if (lastChar == ',') {
  liveVal = liveVal.slice(0, -1);
  }
  $("#preview").text(liveVal);
  });
  });
  </script>
</head>
<body>
  <div>
  <table>
  <tr>
   <td>
  <input type="text" class="myval" value="jaydeep,ankit,krunal,nilesh,chirag," />
  </td>
  <td>
  <button class="removeBtn">Remove</button>
  </td>
  </tr>
  <tr>
  <td>
  <div id="preview" style="color:red;"></div>
  </td>
  </tr>
  </div>
</body>
</html>

Remove last comma using jQuery

index.html

<!DOCTYPE html>
<html>
<head>
  <title> Remove last comma using jQuery </title>
  <script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
  <script type="text/javascript">
    $(function () {
      $('.infiBtn').click(function (event) {
        var liveuserid = $('.mytxt').val();
        var chckend = liveuserid.slice(-1);
        if (chckend == ',') {
          liveuserid = liveuserid.slice(0, -1);
        }
        alert(liveuserid);
      });
    });
  </script>
</head>
<body>
   <div>
    <input type="text" class="mytxt" value="98,22,55,76,02," /><hr /><br />
    <button class="infiBtn">test</button>
  </div>
</body>
</html>

Angular 6 CRUD Operations Application Tutorials
jquery remove last comma from Array
jquery remove last comma from Array

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about jquery check String and remove last comma from string.
I would like to have feedback on my Pakainfo.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.


Related FAQ

Here are some more FAQ related to this Article:

  1.   Remove Last Character from String in JavaScript
  2.   jQuery Ajax change dropdown list value
  3.   Simple Ajax Upload image using jQuery PHP
  4.   Remove Last Character from String jQuery
  5.   javascript remove last comma from string
  6.   Remove Last Comma from String using jQuery
  7.   javascript remove last comma from Array
  8.   jquery remove last comma from Array Example
  9.   Laravel Eloquent Search Filter Example
  10.   How to Get the Value of Selected Option in a Combo Box Using jQuery?