Consider the following code for Google Earth Engine:
var sample_list = ee.List([0, 1, 2, 3]);
var sample_bandNames = ee.List(['B1', 'B2', 'B3', 'B4']);
var sample_function = function(image) {
var var1 = image.select('VAR1');
var var2 = image.select('VAR2');
for (var i = 0; i < sample_list.length; i++) {
var temp = sample_list[i];
var numer = temp.multiply(var1);
var result = numer.divide(var2);
image = image.addBands(result, [ee.String(sample_bandNames[i])]);
}
return image;
}
var img_collection = img_collection.map(sample_function);
I would expect the function to continuously add bands to every image of the image collection, but every time I print the image collection, the number of bands remains unchanged. How can I continuously add bands to each image of the image collection?