In my JavaScript object, I have an associative array containing different values:
var data = [
{val:1, ref:10, rule:100},
{val:1, ref:12, rule:120},
{val:2, ref:13, rule:165},
];
I am looking to find the length of values based on a specific key (for example, when val == 1). Rather than getting the total length of the entire object, I want to specifically calculate the length of values where val is equal to 1. Despite searching for solutions in various resources, I couldn't find a satisfactory answer and I'm uncertain about its feasibility.
data.filter(item => item.val === 1).length; // Output: 2
Something along those lines...