WOLFRAM

Enable JavaScript to interact with content and submit forms on Wolfram websites. Learn how
Wolfram Language & System Documentation Center

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
Details and Options Details and Options
Examples  
Basic Examples  
Scope  
Properties & Relations  
See Also
Related Guides
History
Cite this Page

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

Examples

open all close all

Basic Examples  (3)

Test if a key exists in an association:

Wolfram Language code: KeyExistsQ[<|a -> x, b -> y, c -> z|>, a]
Wolfram Language code: KeyExistsQ[<|a -> x, b -> y, c -> z|>, d]

Test if a key exists in a list of rules:

Wolfram Language code: KeyExistsQ[{a -> x, b -> y, c -> z}, a]
Wolfram Language code: KeyExistsQ[{a -> x, b -> y, c -> z}, d]

Use KeyExistsQ as an operator form:

Wolfram Language code: KeyExistsQ[a][<|a -> x, b -> y, c -> z|>]

Scope  (7)

Use KeyExistsQ on an association:

Wolfram Language code: KeyExistsQ[<|"a" -> 1, "b" -> 2|>, "b"]
Wolfram Language code: KeyExistsQ[<|"a" -> 1, "b" -> 2|>, "c"]

Use KeyExistsQ on a list of rules:

Wolfram Language code: KeyExistsQ[{"a" -> 1, "b" -> 2}, "b"]
Wolfram Language code: KeyExistsQ[{"a" -> 1, "b" -> 2}, "c"]

Test whether a rule has a given key:

Wolfram Language code: KeyExistsQ["a" -> 1, "a"]
Wolfram Language code: KeyExistsQ["a" -> 1, "b"]

Use KeyExistsQ on a TabularRow object:

Wolfram Language code: KeyExistsQ[TabularRow[<|"a" -> 1, "b" -> 2|>], "a"]
Wolfram Language code: KeyExistsQ[TabularRow[<|"a" -> 1, "b" -> 2|>], "c"]

Take a Tabular object with one key column:

Wolfram Language code: tab = ToTabular[{{"a", 1}, {"b", 2}}, "Rows", <|"ColumnKeys" -> {"col1", "col2"}, "KeyColumns" -> "col1"|>]

Check whether given row keys exist in the key column:

Wolfram Language code: KeyExistsQ[tab, RowKey[{"a"}]]
Wolfram Language code: KeyExistsQ[tab, RowKey[{"c"}]]

Use KeyExistsQ on a Dataset object:

Wolfram Language code: KeyExistsQ[Dataset[<|"a" -> 1, "b" -> 2|>], "a"]
Wolfram Language code: KeyExistsQ[Dataset[<|"a" -> 1, "b" -> 2|>], "c"]

KeyExistsQ only checks for the presence of keys at the first level of Dataset :

Wolfram Language code: KeyExistsQ[Dataset[<|"a" -> <|"c" -> 1|>|>], "c"]

Map the operator form of KeyExistsQ over a list of rules:

Wolfram Language code: KeyExistsQ["a"] /@ {"a" -> 1, "b" -> 2}

This checks for the presence of the key in any of the rules:

Wolfram Language code: KeyExistsQ["a"][{"a" -> 1, "b" -> 2}]

It is effectively equivalent to this operation:

Wolfram Language code: AnyTrue[{"a" -> 1, "b" -> 2}, KeyExistsQ["a"]]

Properties & Relations  (2)

KeyExistsQ [data,key] effectively checks whether key is present in Keys [data]:

Wolfram Language code: assoc = <|"a" -> 1, "b" -> 2|>; {Keys[assoc], KeyExistsQ[assoc, "a"], KeyExistsQ[assoc, "c"]}
Wolfram Language code: rules = {"a" -> 1, "b" -> 2}; {Keys[rules], KeyExistsQ[rules, "a"], KeyExistsQ[rules, "c"]}
Wolfram Language code: tr = TabularRow[<|"a" -> 1, "b" -> 2|>]; {Keys[tr], KeyExistsQ[tr, "a"], KeyExistsQ[tr, "c"]}
Wolfram Language code: ds = Dataset[<|"a" -> 1, "b" -> 2|>]; {Normal@Keys[ds], KeyExistsQ[ds, "a"], KeyExistsQ[ds, "c"]}

Take a Tabular object with one key column:

Wolfram Language code: tab = ToTabular[{{"a", 1}, {"b", 2}}, "Rows", <|"ColumnKeys" -> {"col1", "col2"}, "KeyColumns" -> "col1"|>]

KeyExistsQ checks whether a given key exists in the key column:

Wolfram Language code: KeyExistsQ[tab, RowKey[{"a"}]]

ColumnKeyExistsQ checks whether a given column key exists:

Wolfram Language code: ColumnKeyExistsQ[tab, "col2"]
Wolfram Research (2014), KeyExistsQ, Wolfram Language function, https://reference.wolfram.com/language/ref/KeyExistsQ.html.

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: 16-August-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: 16-August-2026]}

Top [フレーム]

AltStyle によって変換されたページ (->オリジナル) /