Problem with create list using for loop in Javascript

I’m trying to crate a code that will count number of images I have and then will create a list with the number of images (for example, if I have 5 images, I’ll get this :
[0,1,2,3,4].

My code runs and I think it creates a list that is empty:
enter image description here

This is my code (I have tried to put only the relevant part):

//First I filter my image collection according to the number of pixels each image has
//Filter according to number of pixels

var ndviWithCount = withNDVI.map(function(image){
  var countpixels = ee.Number(image.reduceRegion({
  reducer: ee.Reducer.count(),
  geometry: geometry,
  crs: 'EPSG:4326',
  scale: 30,
  }).get('NDVI'));

  return image.set('count', countpixels);
});

print(ndviWithCount, 'ndviWithCount');

//Here I count what is the maximum number of pixels that image has and then I create new collection with //only "big images"

var max = ndviWithCount.reduceColumns(ee.Reducer.max(),  ["count"]);
print(max.get('max'));
var max_pix=max.get('max');

//filter between a range
var filter = ndviWithCount.filter(ee.Filter.rangeContains(
          'count', max_pix, max_pix));
print(filter, 'filtered');
//Here I try to grab the number of images so I can create a list
var num_images=filter.size();

//creating the list of images

var listOfImages =(filter.toList(filter.size()));

//Here is the loop that diesn't work
//I have tried to determine i=0, and then that it will iterate untill i is equal to the number of images
//I try to say, i=0, so add 1 and the nadd it to my list.
for (i = 0; i < num_images; i++) {
  var listOfNumbers=[];
  i=i.add(1);
  listOfNumbers.push(i);

}

my end goal is to have list that contains nmbers from 0 or 1 to the number of images I have.

Leave a Reply

Your email address will not be published. Required fields are marked *