UNIQUE

UNIQUE returns an array of unique values taken from the source array.

Function category: Collection

UNIQUE can determine uniqueness across all basic types, including integers, strings, floats, and booleans, but it can also determine uniqueness between complex data structures like hashes, sets, and arrays.

Syntax

UNIQUE(arg1)

Arguments

Description

arg1

Array of values.

Examples

Example 1: Find unique vehicle manufacturers

Let's say we're given a response with the following vehicle information:

{
"data":{
"makes":[
"Toyota",
"BMW",
"Dodge",
"Mercedes Benz",
"Ford",
"BMW",
"GM"
"Nissan"
],
"vehicles":[
{
"make":"Mercedes Benz",
"year":2000
},
{
"make":"BMW",
"year":2002
},
{
"make":"Mercedes Benz",
"year":2000
}
]
}
}

If we are only interested in identifying vehicle manufacturers ("makes") and not their frequency or any other information, we could use UNIQUE:

UNIQUE(data.makes)

This returns the following:

["BMW", "Mercedes Benz", "Toyota"]

Example 2: Find unique vehicles

In this example, we are looking for unique vehicles.

UNIQUE(data.vehicles)

This returns the following:

[{"make":"BMW", "year":2002}, {"make":"Mercedes Benz", "year":2000}]

Example 3: Find unique number set

In this example, we are looking for a unique set of numbers:

UNIQUE({{1, 2, 3, 4, 3}, {1, 2, 3, 4, 3}})

This returns the following:

[1, 2, 3, 4, 3]