Remove Last Comma from String in jQuery

JavaScript Remove Last Character of a String

This blog post demonstrates how to remove last comma from string javascript. Let say I have a string value in a variable strVal, and I need to trim last comma from string. Find the below jQuery code snippet :-
remove last comma from string java,remove last comma from string in jquery,remove last comma from string c#,remove last comma from string in c# net,trim last comma,javascript remove last character of a string
trim last comma
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <title>remove last comma from string jquery</title>
    <script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $('.btnRemove').click(function (event) {
                var strVal = $.trim($('.txtValue').val());
                var lastChar = strVal.slice(-1);
                if (lastChar == ',') {
                    strVal = strVal.slice(0, -1);
                    <input type="text" class="txtValue" value="asp.net mvc, jquery," />
                    <button class="btnRemove">Remove</button>
                    <div id="result" style="color:red;"></div>
Remove Last Comma from String in jQuery Reviewed by Ravi Kumar on 12:45:00 AM Rating: 5

No comments:

All Rights Reserved by Etechpulse © 2012 - 2017
Powered By Blogger

Contact Form


Email *

Message *

Powered by Blogger.