Atom

collection.contains()

Checks key presence.

Signature

collection.contains(collection, key)

Parameters

Array, dict, table or module, and a key.

Returns

Boolean.

Behavior

A stored null still counts as a present key.

Errors

Unsupported receiver.

Example

Atom
use collection
assert(collection.contains({x = null}, 'x'))

Check an array index

For an array the question is whether the index exists, not whether that value appears in the array.

Atom
use collection
scores = [8, 12]
print(collection.contains(scores, 1))
print(collection.contains(scores, 12))
Output
true
false

Index 1 exists. An array of two elements has no index 12.

Check a dictionary key with a null value

Use contains when a missing key and a stored null need different treatment.

Atom
use collection
user = {nickname = null}
print(collection.contains(user, 'nickname'))
Output
true

The nickname key is present, even though its value is null.