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="">
    <title>remove last comma from string jquery</title>
    <script src="" 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=" mvc, jquery," />
                    <button class="btnRemove">Remove</button>
                    <div id="result" style="color:red;"></div>

No comments:

All Rights Reserved by Etechpulse © 2015 - 2016
Powered By Blogger

Contact Form


Email *

Message *

Powered by Blogger.