Version: v0.7.1 - Beta.  We welcome contributors & feedback.

List.getColumn

getColumn($columnKey, $indexKey = '') -> list|map

Description

Get the values from a column in a multi-dimensional List (a List-of-Maps or a List-of-Lists).

If $indexKey is given, it will return a map in the form of { indexValue: columnValue, ... }.

// List of Maps (e.g. from `Db.selectRows`)
$users = [
    { id: 0, name: 'Bob' },
    { id: 1, name: 'Cat' },
    { id: 2, name: 'Ann' },
]

$users.getColumn('name')
//= ['Bob', 'Cat', 'Ann']


// With indexKey
$users.getColumn('name', 'id')
// {
//     0: 'Bob',
//     1: 'Cat',
//     2: 'Ann',
// }

See Also