I have an image collection that spans multiple years. I have looked at each image in the collection and created a list of the image's indices that I'd like to keep for my future analyses. However, I still haven't figure out how to use that index list to filter the entire original image collection and make a new one with my desired images. So far, I have the following:

Let's say that originalCollection is the first collection I obtained.

var imageList = originalCollection.toList(originalCollection.size());
var good_indices = ee.List([0,2,3,5,6,7,10,11,12,14,15,16,17,19,21,28,29,30,31,32,33,34,35,36,37,38,39,40]); 

Then I have tried this:

var i=0; //Index
var good_i = good_indices.get(i);
var img= ee.Image(imageList.get(good_i));

This definitely gives me the first image in the ee.List but I need to iterate over all of the list. I've tried using a loop -although I know it is not recommend:

var i=0;
for (i; i == good_indices.length;i++){
var good_i = good_indices.get(i);
var img= ee.Image(imageList.get(good_i));
var col = ee.ImageCollection(img);

But the result is undefined.

1 Answer 1


I found a way to do it and I am posting the answer in case anyone is interested.

I made a function to get an image for each number in the good_indices list, then mapped this function into function to create an image collection from those images.

function getImages(list){
var img = ee.Image(imageList.get(list));
return img;

var final = ee.ImageCollection.fromImages(good_indices.map(getImages));

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.