This project is read-only.

count([predicate, arg])

Returns a number that represents how many elements in the specified sequence satisfy a condition.

Syntax

Parameters

predicate
Type: function(value, key, arg): boolean
A function to test each element for a condition.
arg
An external argument.
Return Value

Type: number
A number that represents how many elements in the sequence satisfy the condition in the predicate function.

Examples

var fruits = [ "apple", "banana", "mango", "orange", "passionfruit", "grape" ];

var numberOfFruits = $from(fruits).count();
document.writeln("There are " + numberOfFruits + " fruits in the collection.");

// This code produces the following output:
//
// There are 6 fruits in the collection. 

var pets = [ { name: "Barley", vaccinated: true },
             { name: "Boots", vaccinated: false },
             { name: "Whiskers", vaccinated: false } ];

var numberUnvaccinated = $from(pets).count("$vaccinated == false");
document.writeln("There are " + numberUnvaccinated + " unvaccinated animals.");
					
// This code produces the following output:
//
// There are 2 unvaccinated animals.

Last edited May 16, 2012 at 5:11 AM by suckgamoni, version 3

Comments

No comments yet.