I need help setting up two arrays containing dates. The first array should have the dates in string format, while the second array should contain the same dates but as date objects.
methods: {
test() {
let employments = [
{ begin: '01.01.2000', end: '01.01.2010' },
{ begin: '01.01.3000', end: '01.01.3010' },
{ begin: '01.01.4000', end: '01.01.4010' }
];
let items = [];
for(let i = 0; i < employments.length; i++) {
items.push(employments[i]);
}
for(let i = 0; i < items.length; i++ ) {
// splitting it up for the correct format
let begin = items[i].begin.split('.').reverse().join('-');
let end = items[i].end.split('.').reverse().join('-');
items[i].begin = new Date(begin);
items[i].end = new Date(end);
}
console.log('items:');
console.log(items);
console.log('this.employments:');
console.log(employments);
}
}
The intended outcome was to generate two separate outputs - one with strings and the other with date objects. However, I ended up with two arrays containing only date objects. This is not what I expected and I'm unsure why this occurred.
I also attempted to assign employments directly to items like "let items = employments;" instead of using the push method, but this approach did not yield the desired result either.
Any assistance is greatly appreciated.