In my Below Example Im trying to extract a variable from entries("Bookings") The user has made. If one was made on a easter holiday I set a cell on the DB with the date if its not set the value = "" e.g Easteryear = "2022" || Easteryear = ""
on the db.
But Im finding it difficult to extract the latest value that defined. without overwriting it the very next iteration of the loop
Example of the data im looking for is:
Data Filled cells id:1 Easteryear ="2021" || id:2 Easteryear ="2022" || id:3 Easteryear =""
I want the 2022. But My Values keep getting set to Null/NaN
My approach to this is more then likely far from right but I need help extracting the latest value that is not empty in the loop (If I can do it outside a loop would be awesome, However I do need to get that Value so I can set another Variable for later Comparison)
Short Code TLDR: I Tried to Create a Check to see if there are no Values found(A.k.A Easteryear is empty on all entries) Create a Value for the user as if they are here they are booking a value on easter. Then find the latest and set userEasteryear
if(this.personalEntries && this.personalEntries.length){
this.personalEntries.forEach(az => {
if(az.easterYear == null || az.easterYear == "" && easterindex <= 1){
easterindex++;
this.easterYear = year.toString();
return; //Trying to break out oft he loop if this happens, Its a bad idea Thinking about it now.
}else{
var foundEasterYear = parseInt(az.easterYear);
if(foundEasterYear !== NaN ){
userEasteryear = foundEasterYear; //My last ittiration of the if I kept getting leaks
}
az.inbet.forEach(i => {
var x = (i.month+"-"+i.day+"-"+i.year);
personalInbet.push(x);//This is a Temorary Array to Set the Dates Inbtw Start/End Dates
});
}
});
PersonalEntries Structure:
- Surname
- Start Date
- End Date
- InBetween[] //Array of Dates From Start to End Date.
- Easteryear