Javascript - Restructure an array of strings based on prefix
<p>I have an array containing a list of filenames:</p>

<pre><code>var files = ['home_01.ai','home_02.ai','home_03.ai','imprint_01.ai','imprint_02.ai']
</code></pre>

<p>What I want to do is reorganise this array into a multi-dimensional array that groups together each file with the same prefix. In this case:</p>

<pre><code>var firstArray = ['home_01.ai','home_02.ai','home_03.ai'], /*home*/
    secondArray = ['imprint_01.ai','imprint_02.ai']; /*imprint*/
</code></pre>

<p>How could I achieve that when there can be a variable amount of prefixes that can be any length in my file array?</p>