title: How can I cut the string after a second underscore?
body: <p>I'm receiving a list of files in an object and I just need to display a file name and its type in a table.
  All files come back from a server in such format: <code>timestamp_id_filename</code>.</p>
  
  <p>Example: <code>1568223848_12345678_some_document.pdf</code></p>
  
  <p>I wrote a helper function which cuts the string.</p>
  
  <p>At first, I did it with <code>String.prototype.split()</code> method, I used regex, but then again - there was a problem. Files can have underscores in their names so that didn't work, so I needed something else. I couldn't come up with a better idea. I think it looks really dumb and it's been haunting me the whole day.</p>
  
  <p>The function looks like this:</p>
  
  <pre><code>const shortenString = (attachmentName) =&gt; {
      const file = attachmentName
          .slice(attachmentName.indexOf('_') + 1)
          .slice(attachmentName.slice(attachmentName.indexOf('_') + 1).indexOf('_') + 1);
  
      const fileName = file.slice(0, file.lastIndexOf('.'));
      const fileType = file.slice(file.lastIndexOf('.'));
  
      return [fileName, fileType];
  };
  </code></pre>
  
  <p>I wonder if there is a more elegant way to solve the problem without using loops.</p>