Keys macro

Learn how to get the keys of a collection.

This macro gets all the keys or indices of a collection.

The output for maps is the list of keys in the order in which they appear in the map. For lists, the result is the zero-based indices of the elements in the list.

Syntax

This macro has the following syntax:

keys of /*<collection>*/
Try in Playground

You can also prefix the macro with a definite article for readability:

the keys of /*<collection>*/
Try in Playground

Parameters

These are the supported parameters:

collection

The collection from which you want to get the keys or indices.

Examples

Here is an example of how to get the keys of a map:

keys of ["a": 1, "b": 2, "c": 3] // ["a", "b", "c"]
Try in Playground

If you pass a list, you get its indices:

keys of [1, 2, 3] // [0, 1, 2]
Try in Playground