I'm looping through an array of file names, splitting the names, and storing the data in an object. The two file names for testing purposes are identical except for the week "number" which should create two separate weeks. The problem is that the first entry is being overwritten by the last iteration so I end up with an entry for week 2 only.
The code:
const planList = [
'military_greekHero_achilles_week_1.htm',
'military_greekHero_achilles_week_2.htm'
];
var _completePlan = {};
planList.forEach(_plan => {
// Pull data from the file name formated: target_series_title_overview/week_weekNum.htm
let _planPieces = _plan.split('.')[0].split('_'),// Drop 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: {}
}
// _planWeek logs 1 and 2 while iterating but entry for .weeks.1 is overwritten 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 feel like I'm missing something simple... any ideas?