Remove comma (,) from the end of a string in javascript or jquery

Suppost your string is some thing this "1,2,3,4," and you want to remove last comming comma from this string . Below is the javascript code -

<script type="text/javascript">

var comId = '1,2,3,4,' ;
check = comId.slice(-1);
 if(check == ',') {
    
comId = comId .slice(0, -1);

     alert(comId);
 }


</script>

Output : Below is the output of the above javascript code in screne shot -


Remove comma (,) from the end of a string in javascript

Don't forget to leave a comment.

Chears 
Happy Coding :)


Post a Comment

Previous Post Next Post