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

List.indexBy

indexBy($callbackFunction) -> map

Description

Apply $callbackFunction to every item in the list.

The callback function should return a string index key.

Returns a map that points the index keys to each item.

$rows = [
    { id: 0, color: 'red' }
    { id: 1, color: 'green' }
    { id: 2, color: 'green' }
    { id: 3, color: 'blue' }
]

$rows.indexBy(x{ $a.id })

// {
//     '0': { id: 0, color: 'red' }
//     '1': { id: 1, color: 'green' }
//     '2': { id: 2, color: 'green' }
//     '3': { id: 3, color: 'blue' }
// }

See Also