Currently, I am iterating through an array of file names, breaking down the names, and saving the information in an object. For testing purposes, there are two file names that are almost identical except for the week "number" which should represent different weeks. However, I encountered a problem where the first entry is getting overwritten by the last iteration, resulting in only one entry for week 2.
This is the code snippet:
const planList = [
'military_greekHero_achilles_week_1.htm',
'military_greekHero_achilles_week_2.htm'
];
var _completePlan = {};
planList.forEach(_plan => {
// Extract data from the file name format: target_series_title_overview/week_weekNum.htm
let _planPieces = _plan.split('.')[0].split('_'), // Remove the .htm
_planTarget = _planPieces[0],
_planSeries = _planPieces[1],
_planTitle = _planPieces[2],
_planOverview = _planPieces[3],
_planWeek = _planPieces[4];
_planOverview = _planOverview == 'overview' ? true : false;
// Start Building Plan Object
_completePlan[_planTitle] = {
info: {},
weeks: {}
}
// While iterating, _planWeek logs 1 and 2 but the entry for .weeks.1 gets replaced with .weeks.2
_completePlan[_planTitle].weeks[_planWeek] = {
sn: { inactive: true },
mo: { inactive: true },
tu: { inactive: true },
we: { inactive: true },
th: { inactive: true },
fr: { inactive: true },
st: { inactive: true }
}
});
console.log(_completePlan);
});
I believe there might be a simple solution that I'm missing... any suggestions?