jquery - javascript Truncate string after comma -


i'm looking way remove comma , comes after in string, example:

important, not important

i'd remove ",not important"

any ideas? in advance!

you can substring , indexof:

str = str.substring(0, str.indexof(',')); 

but you'd have sure comma in there (test before).

another possibility use split():

str = str.split(',')[0]; 

this works without testing beforehand might perform unnecessary string operations (which negligible on small strings).


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -