Skip to main content
Version: 11.2

Rows.filter()

note

This article is about the filter() function of the Rows object.

Rows.filter()

Filters the rows in scope using a test function.

Returns a new UdbRows object containing only the rows for which function returned a truthy value.

Syntax

$.udb( *ds* ).rows( [rowRef1], [rowRef2] ).filter( *function*( *row*, *index* ) )
$.udb( *ds* ).rowSet( *rowSet* ).rows( [rowRef1], [rowRef2] ).filter( *function*( *row*, *index* ) )

The required ds parameter is a data source selector.

The optional rowSet parameter is a rowset identifier. If the .rowSet() clause is omitted, then .rowSet('current') is assumed.

The optional rowRef1, rowRef2 are row selectors. If omitted, all records in scope are addressed.

The required function is the test function, called once for each row in scope. Inside function, this also refers to the row. The function must return a boolean value for the filtering to function correctly.

Row is the row that the function is currently being applied to. Effectively, this is the same object as this.

Index is the array index of the row for which the function is executed. This index is 0-based.

Example

This example returns rows from the EMP data source that have an AGE value of 65 or higher:

let retiredEmps = $.udb('EMP').rows().filter((row, index) => {
return row.cols('AGE').val() >= 65;
});

You get the same result using this instead, which requires a regular function rather than a lambda:

let retiredEmps = $.udb('EMP').rows().filter(function(row, index) {
return this.cols('AGE').val() >= 65;
});