This question already has an answer here:

How do I display multiple images from an image collection using .map()?

// Create clipping function
var clipper = function(image){
  return image.clip(geometry);

// Load image collection
var modis = ee.ImageCollection('MODIS/006/MOD09GQ').map(clipper);
var months = ee.List.sequence(1,12);

var byMonth = ee.ImageCollection.fromImages(
      months.map(function(m) {
        return modis.filter(ee.Filter.calendarRange(m, m, 'month'))
                    .set('month', m);

// Create a visualization color scheme
var medVis = {
  min: 0, 
  max: 8000,
  palette: [
    'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',
    '66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',
    '012E01', '011D01', '011301'

var display = function(image){
  return Map.addLayer(image,medVis);


I get the following errors when I run the last few lines of code (please use any geometry of your choice): Please reopen the question as a user has a more relevant answer.

Can't encode an undefined value.

Layer 2: Layer error: Failed to decode JSON.
Error: Field 'value' of object '{"type":"ArgumentRef","value":null}' is missing or null.
Object: {"type":"ArgumentRef","value":null}.

Layer 3: Layer error: Failed to decode JSON.
Error: Field 'value' of object '{"type":"ArgumentRef","value":null}' is missing or null.
Object: {"type":"ArgumentRef","value":null}.

marked as duplicate by Community Feb 18 at 21:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Can you provide the complete code? months and modis are not defined above. – JepsonNomad Feb 18 at 21:10
  • @JepsonNomad Done! – Vijay Ramesh Feb 18 at 21:17
  • 3
    I don't think the related answer is exactly what you need. Of course it helps to understand concepts. Here is a code you can use: code.earthengine.google.com/94ce0ce2ccfd75ef3fba81653d65c85f. If the question is reopened, I'll post it as an answer – Rodrigo E. Principe Feb 19 at 1:09
  • Thanks Rodrigo! How do I re-open the question? @RodrigoE.Principe – Vijay Ramesh Feb 19 at 2:20
  • @RodrigoE.Principe I also noticed that using require and importing your functions takes a bit of time. GEE gets stuck for a bit. Is this normal? – Vijay Ramesh Feb 19 at 16:40