In Google Earth Engine, I have an image with 400+ bands that represent probabilities through time when they are group by 3. The bands look something like this

  • prob1_0
  • prob2_0
  • prob3_0
  • prob1_1
  • prob2_1
  • prob3_1 ...
  • prob1_152
  • prob2_152
  • prob3_152

I want to select the 3 bands starting with 0 to get a separate image that I can add to an image collection. I understand how to do it for 1 image (as coded below) but I want to be able to loop over the list variable to create an image collection with 153 images.

var list = ee.List.sequence(0, 152)
var matchKey = '.*' + list.get(0)
var event0 = ee.Image(image400).select(matchKey).clip(studyArea)
var imageCollection = ee.ImageCollection([event0])

How should I go about it?

1 Answer 1


You can use map to loop over each entry in the list to select the bands that match the value of matchKey. Finally, you can use ee.ImageCollection.fromImages to create an image collection from the list of images.

var list = ee.List.sequence(0, 152);

var listImages = list.map(function(number){
  var matchKey = '.*' + number;
  var event0 = ee.Image(image400).select(matchKey);
  return event0;

var imageCollection = ee.ImageCollection.fromImages(listImages);

Your Answer

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

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