'Trying to separate sql DB values from each other

function absent() {
    const absent_date = new Date();
    const absent_days = absent_date.getDay();

    console.log("days", absent_days);
    let absent_remove = result_database.map(item => item.absentday)
    console.log("absent_remove", absent_remove);
    if (absent_remove == absent_days) {
        console.log("it works?")
        //resultStatement();
    } else {
        console.log("it doesnt work")
    }
}

I'm trying to separate the DB values below from each other, I have absent_remove 3 and 5, these numbers stand for the days someone is absent. From absent_days I would get lets say 5 (Friday), The DB value 3 should NOT be absent, and the DB value 5 SHOULD, but since they're in an array they interfer with each other, I need the DB value 5 to be selected everytime getDay() is 5. And DB val 3 when the day is 3. Anyone that can help me out here?

days 5
absent_remove [ 3, 5 ]
it doesnt work


Solution 1:[1]

Use find() to return only the element that matches the current day.

function absent() {
    const absent_date = new Date();
    const absent_days = absent_date.getDay();
    console.log("days", absent_days);
    let absent_remove = result_database.map(item => item.absentday).find(day => day == absent_days)
    console.log("absent_remove", absent_remove);
    if (absent_remove == absent_days) {
        console.log("it works?")
        //resultStatement();
    } else {
        console.log("it doesnt work")
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Barmar