/* Returns a list of objects that have a matching property value. */
// Updated 2023-06-28
export const get_obj_li_w_match_prop = function get_obj_li_w_match_prop({
    obj_li,
    property,
    value,
    log_lvl = 0
}: {
    obj_li: any[];
    property: string;
    value: any;
    log_lvl?: number;
}) {
    if (log_lvl) {
        console.log('Search Object List:', obj_li);
        console.log(`Property: ${property}`);
        console.log(`Value: ${value}`);
    }
    if (log_lvl > 1) {
        console.log(`Type Of: ${typeof value}`);
    }

    // Create an empty array to store the matching objects.
    const matching_obj_li = [];

    // Iterate through the list of objects.
    for (const object of obj_li) {
        // Check if the object has the specified property and the value of the property matches the specified value.
        if (object.hasOwnProperty(property)) {
            // console.log('Has property at least....', object[property], typeof object[property]);
        }
        if (object.hasOwnProperty(property) && object[property] === value) {
            // Add the object to the array of matching objects.
            matching_obj_li.push(object);
        }
    }

    // Return the array of matching objects.
    if (log_lvl > 1) {
        console.log('Matching Object List:', matching_obj_li);
    }
    return matching_obj_li;
};
