Open this page in the API Guide

Enumerable.first Method

Returns the first element of the sequence. If "predicate" is provided, returns the first element that satisfies that condition.
 
 
Static This method is static.

Parameters

source

Type: IEnumerable
The enumerable to return the first element of.
predicate

Type: Function - May be null
A function to test each element for a condition, returning true or false.
Optional: True

Return Value


Type: Object - May be null
The first element of the sequence that satisfies the specified condition. 

Examples

This example was placed on a button click event. It uses the first method to get the first item with the name of viewParameter1.

1
2
3
4
5
6
7
8
9
10
11
12
13
// Get the parent view.
var parentView = this.parentView;
 
// Get the view parameters.
var viewParameters =
    parentView.control.viewParameters;
 
// Using the library, get the view parameter based on it's name
var viewParameter =
    viewParameters.toEnumerable().first(
      function (viewParameterItem) { return viewParameterItem.name === "viewParameter1";}
    );