I want to be able to access an array so that I can loop over it either manually or with a forEach function etc. Currently I am getting an Array of length 0 however it does have objects with in it accessed by array.name. Alternatively I wouldn't mind keeping the current data structure if I knew how to loop through it. Here is my code:
Edit - I should probably be looking at key/value pairs?
var renameFiles = function renameFiles(files) {
var map = [];
var reg = /\(\d+\)/;
files.filter(function(file) {
if(!map[file.replace(reg, '')]) {
map[file.replace(reg, '')] = [file];
} else if (!map[file] && !file.match(reg)) {
map[file] = [file];
} else if (map[file.replace(reg, '')]) {
map[file.replace(reg, '')].push(file);
} else {
map[file].push(file);
}
});
return map;
};
f = ['a(1)', 'a(6)', 'a','a','a','b','b(1)','b(4)','c','c(2)'];