So this next function should search in a pre-stored array, inside chrome storage, a certain index equals to the current date:
function comparingDates(fn) {
var currentDate = new Date();
var j;
chrome.storage.sync.get("storeDates", function comparing(items) {
if (!chrome.runtime.error) {
var arrayDates = items.storeDates;
j = arrayDates.findIndex(x => x.date == currentDate.getDate());
console.log(j);
fn(j);
};
});
};
With fn
being the function that will send the corresponding index found to this callback:
comparingDates(function (l1) {
if (!l1) {
console.log("error");
} else {
currentDay = l1;
console.log("succes");
};
the variable currentDay
is declared before.
After the function is run and the value is sent, takes the condition when l1
is undefined.
Not knowing full well how to handle async functions is difficult to get a good grasp were the error occurs. And doing some search about it, doesn't provide with good examples for pratical references.