Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

first([predicate, arg])

suckgamoni edited this page · 1 revision

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.


Example

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

console.log(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");

console.log(first);

/*
 This code produces the following output:

 92
*/
Something went wrong with that request. Please try again.