'How can I get the number of items in a filtered array in JavaScript

I was trying to divide the number of items in a filtered array but it kept showing me undefined, NAN, or the number of letters in that particular filter when I send it to the console. But what I want to get is the number of items in the filter.

Here is the code I wrote: for (let i = 0; i < categories.length; i++) {

categories[i].addEventListener('click', (e) => {

    const filterF = e.target.dataset.category;

    dogProducts.forEach((product) => {
        if (product.classList.contains(filterF)) {
            product.style.display = 'block';
            ulTag.style.display = 'none';

            console.log(products);

        } else {
            product.style.display = 'none';
            ulTag.style.display = 'none';
        }

    })
})

}



Sources

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

Source: Stack Overflow

Solution Source