title: Javascript - Removing last 3 words from a string
body: <p>I've been able to find examples of how to remove the last word of a string, but in this instance I'm attempting to remove the last 3 words of a string. I've attempted this by adjusting some of the answers I've come across to remove a single word but none have gave me the expected results.</p>
  <p>Example string <code>Highest ranked in the states</code></p>
  <p>I would like my return value be <code>Highest ranked</code></p>
  <p>Here are some code snippets of what I've attempted:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>let myString = "Highest ranked in the states";
  
  myString = myString.substring(2, myString.lastIndexOf(" "));
  
  console.log(myString)
  
  
  let myString2 = "I want to remove the last word";
  let mySplitResult2 = myString2.split(" ");
  let lastWord =  mySplitResult2[mySplitResult2.length-3] 
  
  console.log(lastWord)</code></pre>
  </div>
  </div>
  </p>
  <p>with the adjusting the substring method to <code>(2, myString.lastIndexOf(&quot; &quot;));</code> it ended up removing the first two letters of my sentence and only removed the word <code>states</code> such as &quot;guest ranked in the&quot;</p>
  <p>when adjusting the .split() method to length -3 it simply returns back the word <code>in</code> instead of <code>in the states</code></p>