KeyExistsQ[assoc,key]
returns True if the specified key exists in the association assoc, and False otherwise.
KeyExistsQ[key]
represents an operator form of KeyExistsQ that can be applied to an expression.
KeyExistsQ
KeyExistsQ[assoc,key]
returns True if the specified key exists in the association assoc, and False otherwise.
KeyExistsQ[key]
represents an operator form of KeyExistsQ that can be applied to an expression.
Details
- KeyExistsQ can be applied not only to Association objects, but also to related objects such as rules, lists of rules, Dataset objects, TabularRow objects and Tabular expressions with a key column.
- KeyExistsQ[key][expr] is equivalent to KeyExistsQ[expr,key].
Examples
open all close allBasic Examples (3)
Test if a key exists in an association:
KeyExistsQ[<|a -> x, b -> y, c -> z|>, a]KeyExistsQ[<|a -> x, b -> y, c -> z|>, d]Test if a key exists in a list of rules:
KeyExistsQ[{a -> x, b -> y, c -> z}, a]KeyExistsQ[{a -> x, b -> y, c -> z}, d]Use KeyExistsQ as an operator form:
KeyExistsQ[a][<|a -> x, b -> y, c -> z|>]Scope (7)
Use KeyExistsQ on an association:
KeyExistsQ[<|"a" -> 1, "b" -> 2|>, "b"]KeyExistsQ[<|"a" -> 1, "b" -> 2|>, "c"]Use KeyExistsQ on a list of rules:
KeyExistsQ[{"a" -> 1, "b" -> 2}, "b"]KeyExistsQ[{"a" -> 1, "b" -> 2}, "c"]Test whether a rule has a given key:
KeyExistsQ["a" -> 1, "a"]KeyExistsQ["a" -> 1, "b"]Use KeyExistsQ on a TabularRow object:
KeyExistsQ[TabularRow[<|"a" -> 1, "b" -> 2|>], "a"]KeyExistsQ[TabularRow[<|"a" -> 1, "b" -> 2|>], "c"]Take a Tabular object with one key column:
tab = ToTabular[{{"a", 1}, {"b", 2}}, "Rows", <|"ColumnKeys" -> {"col1", "col2"}, "KeyColumns" -> "col1"|>]Check whether given row keys exist in the key column:
KeyExistsQ[tab, RowKey[{"a"}]]KeyExistsQ[tab, RowKey[{"c"}]]Use KeyExistsQ on a Dataset object:
KeyExistsQ[Dataset[<|"a" -> 1, "b" -> 2|>], "a"]KeyExistsQ[Dataset[<|"a" -> 1, "b" -> 2|>], "c"]KeyExistsQ only checks for the presence of keys at the first level of Dataset:
KeyExistsQ[Dataset[<|"a" -> <|"c" -> 1|>|>], "c"]Map the operator form of KeyExistsQ over a list of rules:
KeyExistsQ["a"] /@ {"a" -> 1, "b" -> 2}This checks for the presence of the key in any of the rules:
KeyExistsQ["a"][{"a" -> 1, "b" -> 2}]It is effectively equivalent to this operation:
AnyTrue[{"a" -> 1, "b" -> 2}, KeyExistsQ["a"]]Properties & Relations (2)
KeyExistsQ[data,key] effectively checks whether key is present in Keys[data]:
assoc = <|"a" -> 1, "b" -> 2|>;
{Keys[assoc], KeyExistsQ[assoc, "a"], KeyExistsQ[assoc, "c"]}rules = {"a" -> 1, "b" -> 2};
{Keys[rules], KeyExistsQ[rules, "a"], KeyExistsQ[rules, "c"]}tr = TabularRow[<|"a" -> 1, "b" -> 2|>];
{Keys[tr], KeyExistsQ[tr, "a"], KeyExistsQ[tr, "c"]}ds = Dataset[<|"a" -> 1, "b" -> 2|>];
{Normal@Keys[ds], KeyExistsQ[ds, "a"], KeyExistsQ[ds, "c"]}Take a Tabular object with one key column:
tab = ToTabular[{{"a", 1}, {"b", 2}}, "Rows", <|"ColumnKeys" -> {"col1", "col2"}, "KeyColumns" -> "col1"|>]KeyExistsQ checks whether a given key exists in the key column:
KeyExistsQ[tab, RowKey[{"a"}]]ColumnKeyExistsQ checks whether a given column key exists:
ColumnKeyExistsQ[tab, "col2"]See Also
Lookup Keys MemberQ FreeQ ColumnKeyExistsQ ColumnKeys Missing
Related Guides
History
Text
Wolfram Research (2014), KeyExistsQ, Wolfram Language function, https://reference.wolfram.com/language/ref/KeyExistsQ.html.
CMS
Wolfram Language. 2014. "KeyExistsQ." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/KeyExistsQ.html.
APA
Wolfram Language. (2014). KeyExistsQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/KeyExistsQ.html
BibTeX
@misc{reference.wolfram_2026_keyexistsq, author="Wolfram Research", title="{KeyExistsQ}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/KeyExistsQ.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_keyexistsq, organization={Wolfram Research}, title={KeyExistsQ}, year={2014}, url={https://reference.wolfram.com/language/ref/KeyExistsQ.html}, note=[Accessed: 13-June-2026]}