For my current project, I am using LocalStorage to store an array of dates and costs. When the code localStorage.getItem("todos");
is executed in the console, the output looks like this:
"[{"due":"28/10/2017","task":"80"},{"due":"06/10/2017","task":"15"}]"
In this array, "due" represents the date and "task" represents the amount.
I have successfully calculated the total cost by utilizing the following method:
total: {
type: String,
value: () => {
var values = localStorage.getItem("todos");
if (values === undefined || values === null) {
return "0";
}
var data = JSON.parse(values);
var sum = 0;
data.forEach(function(ele){ sum+=Number(ele.task)}); return sum;
}
}
My next challenge is to calculate the total cost for the past six months. I am unsure about the approach that should be taken to accomplish this task. Any suggestions on how I can achieve this?