Skip to content

isSubset - Check if one array is contained within another array

Returns true if array1 is a subset of array2.

NOTE: When comparing array1 and array2, duplicates will be discarded. This means two arrays of differing lengths but the same unique elements will be considered equal.

Syntax

isSubset(array1: array<T>, array2: array<T>): bool

Arguments

Name Type Required Description
array1 array of type T true T must be either string, bool, number, interval, timestamp, regexp or enum
array2 array of type T true T must be either string, bool, number, interval, timestamp, regexp or enum

Example - Basic usage

Consider the following document:

{
    "all_jobs": ["Chris", "John", "Adam", "Ariel", "Zev"],
    "started_jobs": ["Chris", "John"]
}

If we wish to check that started_jobs is a subset of all_jobs, we can do the following:

create is_subset from started_jobs.isSubset(all_jobs)

This results in the following document:

{
    "all_jobs": ["Chris", "John", "Adam", "Ariel", "Zev"],
    "started_jobs": ["Chris", "John"],
    "is_subset": true
}