distinct

Modified on Thu, 9 Jul at 10:49 AM

distinct

TABLE OF CONTENTS

Get unique items from an array

Definition

array distinct(array $input)

Gets distinct items from $input array based on token equality.

Parameters

array $input

Array to be checked for duplicates.

Returns

array

Array after removing the duplicates.

Examples

Transfomation
{
  letters: distinct(['a', 'b', 'a']),
  objects: distinct([{name:`"Joe"`, id:`1`}, {name:`"Joe"`, id:`1`}]),
  zeros: distinct([`0.00`,`0.0`,`0`,`null`,`false`])
}
Result
{
  "letters": [
    "a",
    "b"
  ],
  "objects": [
    {
      "name": "Joe",
      "id": 1
    }
  ],
  "zeros": [
    0.0,
    null,
    false
  ]
}

Remarks

Elements a and b are considered distinct if and only if a==b evaluates to false . Read more about equality in JMESPath.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article