How to Remove the Last Word in the String Using JavaScript, How can I Remove the Last Word From a String with Javascript
Hello friends So today I will tell you through these tutorials how to remove the last words from the value of any string with JavaScript.
So first I made a variable and passed the string value in it.And now with the help of some inbuilt Jvascript function, we will remove the last word from the string value given in this variable.
<script> var str = "I want to remove the last word."; var lastword = str.lastIndexOf(" "); str = str.substring(0, lastword); alert(str) </script>