The .select() function is the last function to be called in the chain. It returns the final array of objects.

📘

The .select() can be used for the following:

  • Restricting the columns that are returned
  • Defining the order of columns
  • Changing column names
  • Creating constant value columns
  • Adding calculated columns by using a predicate
  • Transforming to a new object

No Parameter

When using the .select() with no parameters all the fields are returned in the array and the order of the fields are also not defined.

select()
select<T>(): T[];

String Parameters

To specify the order and what fields to return, specify the field names as parameters in a set order.

select( string, string, string, …)
select<T>(field: string, ...fields: string[]): T[];

Single Parameter Containing An Array Of Objects

You can add fine grain control to the columns to be returned by specifying an array of objects. The order of the objects in the array define the order the columns are returned in the result. The select object is defined as follows:

{
     field: ‘ColumnName or position#’, <= (Optional)
     text: ‘ColumnText’,               <= (Optional, change the field name)
     value: string | predicate(row)    <= (Optional, hard coded value or predicate for
     																				a calculated column)
} ,,,
select( Array(Object, Object, Object, …) )
type PredicateSelect<T> = (row: T) => T;
interface selectParameter<T> {
  field?: number | string;
  text?: string;
  value?: any | PredicateSelect<T>;
}

select<T>(selectParameters: selectParameter<T>[]): T[]

Predicate Parameter

In some cases you might want full control of how the returned collection is returned.

📘

The select predicate can be used to restructure the returned collection. For example if the collection that you are querying from is not flat and has nested objects and arrays.

select( Function( row, index ) )
Predicate<TRow, TResult> = (row: TRow, index: number) => TResult;

select<T>(predicate: Predicate<T, T>): T[];
select<TRow, TResult>(predicate: Predicate<TRow, TResult>): TResult[];