I'm trying to figure out a way to get a list of unique values in a ee.List() object. For example:

input=ee.List([1,1,1,4,4,5,6,6]) output=[1,4,5,6]

I originally thought I could use the ee.List.distinct() function, but this does not appear to be an actual valid function. Since then I've tried a variety of different approaches including a variation of the solution to this related question to no avail.

My current approach involves an iterator function that appends newly encountered values to a new "unique values" list, however it just seems to be recognizing every value as unique and outputting the original list.

Here is my code:

var test_list=ee.List([1,1,1,4,5,6,6])
var iterlist=ee.List([])

function unique_list(inputItem, distinct_values){
  var number=ee.Number(inputItem);
  return distinct_values;

var result=test_list.iterate(unique_list, iterlist)
print('unique list is', result)

1 Answer 1


There is an ee.List.distinct() method.

ee.List([1, 1, 1, 4, 5, 6, 6]).distinct()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.