Search

Dark theme | Light theme

January 25, 2026

Nushell Niceties: Checking If Value Is In List Or String Or Key In Record

Nushell has the in operator to check if a value is an element of list. With the same in operator you can check if a string is a substring of another string. And finally you can use the in operator to check if a key is in a record. When you use the operator the value you want to check is defined before the operator and the list, other string or record is defined after the operator.
The not-in operator is the opposite of the in operator and checks if a value is not in list or other string or key in a record.
It is also possible to use the has and not-has operators to do the same checks, but the value you want to check is set after the operator. The list, other string or record is set before the operator.

In the following example the operators are used with lists:

use std/assert

# Using in operator to check if a value is in a list.
assert (1 in [1 2 3 4])
assert ('Nushell' in ['Nushell' 'rocks'])

# Using not-in operator to check if a value is not in a list.
assert (1 not-in [2 3 4])
assert ('nushell' not-in ['Nushell' 'rocks'])


# Using has operator to check if a value is in a list.
assert ([1 2 3 4] has 1)
assert (['Nushell' 'rocks'] has 'Nushell')

# Using not-has operator to check if a value is not in a list.
assert ([1 2 3 4] not-has 5)
assert (['Nushell' 'rocks'] not-has 'nushell')

In the following example the operators are used with strings:

use std/assert

# Using in operator to check if a value is in a string.
assert ('Nushell' in 'Nushell rocks!')

# Using not-in operator to check if a value is not in a string.
assert ('awesome' not-in 'Nushell rocks!')


# Using has operator to check if a value is in a string.
assert ('Nushell rocks' has 'Nushell')

# Using not-has operator to check if a value is not in a string.
assert ('Nushell rocks' not-has 'awesome')

In the following example the operators are used with records:

use std/assert

# Using in operator to check if a key is in a record.
assert ('name' in {name: 'mrhaki' location: 'Tilburg'})

# Using not-in operator to check if a key is not in a record.
assert ('age' not-in {name: 'mrhaki' location: 'Tilburg'})


# Using has operator to check if a key is in a record.
assert ({name: 'mrhaki' location: 'Tilburg'} has name)

# Using not-has operator to check if a key is not in a record.
assert ({name: 'mrhaki' location: 'Tilburg'} not-has age)

Written with Nushell 0.110.0.