I'm trying to transform client-side functions to server function in GEE. However, I cannot obtain the desired result for the function named "add to list". The problem is that I want to add new elements from a list to another list one by one. But the result that I'm obtaining is the first list and then the other one.


// Add fixed vallues to a list CLIENT SIDE
var addToList_ClientSide = function(list, season){
  var ini_season = season[0]
  var end_season = season[1]
  var years_seq = [];
  for (var i = 0; i < list.length; i++){
    var el = [list[i], ini_season, end_season]
  return years_seq

// Add fixed vallues to a list SERVER SIDE
var addToList_ServerSide = function(list, season){
  var ini_season = season.get(0)
  var end_season = season.get(1)
  var years_seq = ee.List.sequence(list.get(0), list.get(-1))
  var el = ee.List([ini_season, end_season])
  return years_seq.add(el)

1 Answer 1


The direct correspondence to your for loop is a map over a number sequence:

var addToList_ServerSide = function(list, season){
  var ini_season = season.get(0);
  var end_season = season.get(1);
  var years_seq = ee.List.sequence(0, list.length().subtract(1))
    .map(function (i) {
      return ee.List([list.get(i), ini_season, end_season]);
  return years_seq;

print(addToList_ClientSide(['a', 'b', 'c'], ['d', 'e']));
print(addToList_ServerSide(ee.List(['a', 'b', 'c']), ee.List(['d', 'e'])));
// Both of the above print [["a","d","e"],["b","d","e"],["c","d","e"]]


I don't know if this necessarily does what you want, but it will do the same list manipulation as your addToList_ClientSide.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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