any([predicate, arg])

Determines whether any element of a sequence satisfies a condition.

Syntax

Parameters

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

Type: boolean
true if any elements in the source sequence pass the test in the specified predicate; otherwise, false.

Examples

var numbers = [ 1, 2 ];
var hasElements = $from(numbers).any();

document.writeln("The list " + (hasElements ? "is not" : "is") + " empty.");

// This code produces the following output:
//
// The list is not empty. 

// Create an array of Pets.
var pets = [
    { name: "Barley", age: 8, vaccinated: true },
	{ name: "Boots", age: 4, vaccinated: false },
	{ name: "Whiskers", age: 1, vaccinated: false } 
];

// Determine whether any pets over age 1 are also unvaccinated.
var unvaccinated = $from(pets).any("$age > 1 && $vaccinated == false");

document.writeln("There " + (unvaccinated ? "are" : "are not any") + " unvaccinated animals over age one.");

// This code produces the following output:
//
//  There are unvaccinated animals over age one. 

Last edited May 15, 2012 at 12:45 PM by suckgamoni, version 2

Comments

No comments yet.