first([predicate, arg])

Returns the first element in a sequence that satisfies a specified 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

The first element in the sequence that passes the test in the specified predicate function.

Examples

var numbers = [ 9, 34, 65, 92, 87, 435, 3, 54, 83, 23, 87, 435, 67, 12, 19 ];

var first = $from(numbers).first();

document.writeln(first);

/*
 This code produces the following output:

 9
*/

var numbers = [ 9, 34, 65, 92, 87, 435, 3, 54, 83, 23, 87, 435, 67, 12, 19 ];

var first = $from(numbers).first("$ > 80");

document.writeln(first);

/*
 This code produces the following output:

 92
*/

Last edited May 16, 2012 at 7:34 AM by suckgamoni, version 1

Comments

No comments yet.