Skip to main content
Version: 11.2

$.udb(ds).each()

note

This article is about the each() function of the DataSourceContainer object.

$.udb(ds).each()

Asynchronally iterates the execution of a function over the matched data sources.

Returns a UdbPromise object.

Syntax

$.udb( *ds* ).each( *function*( *index*, *object* ) )
.then( ( *dsc* ) => {
// success
})
.catch(() => {
// failure
})
.finally(() => {
// executed after success / failure is handled
});

The required ds parameter is a data source selector.

The parameter dsc in the resulting UdbPromise clause is the same data source container on which the function was executed.

Function is the function that is to be called for each of the matched data sources.

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

Object is the object itself. Effectively, object is the same object as returned to the .then() clause as its dsc parameter.

note

The function called for each data source is executed asynchronously. In order to have every call executed correctly as part of the UdbPromise promise-chain, have it return the (Udb)Promise value in the function.

This function differs from the native Array function .forEach() which just iterates over every element of the collection, in the way that the results of the function executed by .each() is chained into a UdbPromise.all() clause here, allowing chained asynchronous execution.

Example

$.udb(['EMP','DEPT']).each((index, ds) => {
return ds.executeQuery();
});