all(predicate[, arg])

Determines whether all elements of a sequence satisfy a condition.

Syntax

Parameters

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

Type: boolean
true if every element of the source sequence passes the test in the specified predicate, or if the sequence is empty; otherwise, false.

Examples

// Create an array of Pets.
var pets = [ { name: "Barley", age: 10 },
			 { name: "Boots", age: 4 },
			 { name: "Whiskers", age: 6 } ];

// Determine whether all pet names 
// in the array start with 'B'.
var allStartWithB = $from(pets).all("$name[0] == 'B'");

document.writeln((allStartWithB ? "All" : "Not all") + " pet names start with 'B'.");

// This code produces the following output:
//
//  Not all pet names start with 'B'. 


var people = [
    { lastName: "Haas",
      pets: [ { name: "Barley", age: 10 },
              { name: "Boots", age: 14 },
              { name: "Whiskers", age: 6 } ] },
    { lastName: "Fakhouri",
	  pets: [ { name: "Snowball", age: 1 } ] },
    { lastName: "Antebi",
	  pets: [ { name: "Belle", age: 8 } ] },
    { lastName: "Philips",
	  pets: [ { name: "Sweetie", age: 2 },
	          { name: "Rover", age: 13 } ] }
];

// Determine which people have pets that are all older than 5.
var names = $from(people)
    .where("$from($pets).all('$age > 5')")
    .select("$lastName");

names.each("document.writeln($)");

/* This code produces the following output:
 * 
 * Haas
 * Antebi
 */	 

Last edited May 15, 2012 at 7:41 AM by suckgamoni, version 3

Comments

No comments yet.