javascript - Remove comma to the last string -


i have code:

$(".value").append($("#txtvalue").val()).attr("class", "values"); 

example: if #txtvalue value 'apple, banana,' how can remove comma (, ) last last value using code have in above or if detected value has last string of comma (,). want have value this: 'apple, banana'

another solution regexp method think.

<html> <head></head> <body>     <script>             //make .trim() before         var stuff = "apple, banana,";          var result = (stuff.substr(stuff.length-1, 1) == ",")? stuff.substr(0, stuff.length-1):stuff;         alert(result);     </script> </body> </html> 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -