-
Notifications
You must be signed in to change notification settings - Fork 3
Count
Yasser Moradi edited this page Sep 1, 2015
·
1 revision
Description:
This method returns the numbers of item in the collection. It has a predicate argument and returns number of items in the collection which pass the predicate.
Samples:
let stock = [
{ name: 'Apple', category: 'Fruit', price: 0.30 },
{ name: 'Banana', category: 'Fruit', price: 0.35 },
{ name: 'Orange', category: 'Fruit', price: 0.29 },
{ name: 'Cabbage', category: 'Vegetable', price: 0.49 },
{ name: 'Carrot', category: 'Vegetable', price: 0.29 },
{ name: 'Lettuce', category: 'Vegetable', price: 0.30 },
{ name: 'Milk', category: 'Dairy', price: 1.12 }
];
console.log('stock item count => ' + stock.asEnumerable().count());
console.log('Number of stockItems which are Fruit => ' +
stock.asEnumerable().count(item => item.category == 'Fruit'));
/*This code: */ stock.asEnumerable().count(item => item.category == 'Fruit') /* is equivalent to */ stock.asEnumerable().where(item => item.category == 'Fruit').count()