title: Get filename from URL using JavaScript
body: <p>I have a script that grabs the filename from a URL but I have a problem.</p>
  
  <p>Firstly, here's what I've got so far:</p>
  
  <pre><code>var img = $('img').attr('src'),
  fileName_Index = img.lastIndexOf("/") + 1,
      fileName = img.substr(fileName_Index);
  </code></pre>
  
  <p>If the URL was to have <code>?format=foo</code> after the filename, that part is added. Is there a way to remove the last part starting with the question mark leaving just the filename?</p>