title: Javascript: Returning the last word in a string
body: <p>right to it:</p>
  
  <p>I have a <code>words</code> string which has two words in it, and i need to return the last word. They are seperated by a " ". How do i do this?</p>
  
  <pre><code>function test(words) {
  
  var n = words.indexOf(" ");
  var res = words.substring(n+1,-1);
  return res;
  
  }
  </code></pre>
  
  <p>I've been told to use <code>indexOf</code> and <code>substring</code> but it's not required. Anyone have an easy way to do this? (with or without <code>indexOf</code> and <code>substring</code>)</p>