Skip to content

Map

Converts all rows in the table to the return value of the given callback function.

1
myDataTable.Map(fn: (this: DataRow, row: DataRow, i: number) => any):Array<any>

Parameters

(this: DataRow, row: DataRow, i: number) => any fn
    A function to call for every row. Inside the function, this is the row; the arguments are the row and its index.

Returns

An array containing the results of the callback function for each row.

Remarks

When the callback returns undefined or null, the row itself is added to the result.

Examples

Convert rows to plain objects

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
var groups = $Database.Get({
    TargetSchema : 'HR',
    TargetTable : 'Groups'
});

var items = groups.Map(function (row) {
    return {
        id : row.Id,
        name : row.Name
    };
});
// [{ id : '...', name : 'Administrators' }, { id : '...', name : 'Reviewers' }]

Collect the values of a column

1
2
3
var ids = $Database.GetData('Sales', 'Orders', 'Status', 'New').Map(function () {
    return this.Id;
});