I would like to know how can I remove the last word in the string using JavaScript?
For example, the string is \"I want to remove the last word.\"
After usin
You can do a simple regular expression like so:
"I want to remove the last word.".replace(/\w+[.!?]?$/, '') >>> "I want to remove the last"
Finding the last index for " " is probably faster though. This is just less code.
" "