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
Post a Comment