UPDATE
I missed that you may have another prefixes. Updated for using with any prefix.
function splitFilesIntoTypes(_files, cb) {
var result = [];
// loop through the array
_files.map(function(a, b){
if(!result[a.split('_')[0]])
result[a.split('_')[0]] = [];
result[a.split('_')[0]].push(a);
});
return result
}
var files = ['another_01.ai','home_01.ai','home_02.ai','home_03.ai','imprint_01.ai','imprint_02.ai'];
console.log(splitFilesIntoTypes(files));
FIXED
Supposing you have only two types of names (home_... and imprint_...). I made this function to split it into two arrays.
// function takes array and returns two array to callback function
function splitFilesIntoTypes(_files, cb) {
// if you have only two types of names
var _home = [], _imprint = [];
// loop through the array
_files.map(function(a, b){
if(a.split('_')[0] === 'home') _home.push(a);
if(a.split('_')[0] === 'imprint') _imprint.push(a);
});
if(typeof cb === "function")
cb(_home, _imprint);
}
var files = ['home_01.ai','home_02.ai','home_03.ai','imprint_01.ai','imprint_02.ai'];
splitFilesIntoTypes(files, function(firstArray, secondArray) {
console.log(firstArray);
console.log(secondArray);
});