Keys

Keys[key1val1,key2val2,]

gives a list of the keys keyi in an association.

Keys[{key1val1,key2val2,}]

gives a list of the keyi in a list of rules.

Keys[expr,h]

gives a list of keys in expr, wrapping each of them with head h before evaluation.

Details

  • Keys maintains the order of keys.
  • Keys[key->val] gives key.
  • Use Keys[expr,Hold] to extract keys without letting them evaluate.

Examples

open all close all

Basic Examples  (4)

Get the keys in an association:

In[1]:=
Click for copyable input
Out[1]=

Get keys from a list of rules:

In[1]:=
Click for copyable input
Out[1]=

Keys automatically threads over lists:

In[1]:=
Click for copyable input
Out[1]=

Wrap keys with Hold to prevent evaluation:

In[1]:=
Click for copyable input
Out[1]=

Properties & Relations  (3)

Introduced in 2014
(10.0)
|
Updated in 2019
(12.0)