My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
select  
Overview of select
Updated Sep 2, 2010 by matr...@mac.com

select

Action that selects objects from an array depending on the result of the decider. This is the opposite of reject.

Usage

objx( array ).select( decider [, behaviour);

array The array containing the objects to select from
decider (required) The decider to use to decide which items are selected
behaviour (required if the decider is a function) Usually should be ONew, see actions

Example

var selectTestObjects = [
	{ name: "Mat", age: 26 },
	{ name: "Simon", age: 23 },
	{ name: "Laurie", age: 25 },
	{ name: "Chris", age: 21 },
	{ name: "Corey", age: 1 }
];

// select objects whose age is below 22
objx(selectTestObjects).select({age: {below: 22}}, ONew);

// returns [{ name: "Chris", age: 21 }, { name: "Corey", age: 1 }]

// select objects whose name begins with `C`
objx(selectTestObjects).select(function(n){ return n.name.substr(0,1)=="C"; }}, ONew);

// returns [{ name: "Chris", age: 21 }, { name: "Corey", age: 1 }]

See also


Sign in to add a comment
Powered by Google Project Hosting