var str = "I want to remove the last word."; var lastIndex = str.lastIndexOf(" "); str = str.substring(0, lastIndex);