You can use Array.filter here `var count = items.filter(filter).length;`