DS Server

Javascript: Collection.elementAt Method

Method|Introduced in 28.0

Description

Returns the element at a specified index in the collection.

Syntax

<void> Collection.elementAt(<number> index, <RequestObjectCallback> callback, [<ErrorCallback> errorCallback])

Parameters

ParameterDescription
index

The zero-based index of the element to retrieve.

callback

Receives the element as a parameter.

errorCallback

Optional. Is called when the operation failed with an error.

Examples

The following example demonstrates Collection.elementAt in a practical document-editing workflow. It returns the element at a specified index in the collection.

function onTxError(error) {
    console.error("TX Text Control error:", error.msg);
    error.handled = true;
}

function elementAt(s) {
    s.elementAt(
        0,
        function(obj) {
            if (!obj) {
                console.warn("No object was returned.");
                return;
            }
            
            console.log("element at result:", obj);
        },
        onTxError
    );
}