Search code examples
arrayslistimagevargoogle-earth-engine

How to sum up the first 5 list values in the list of numbers in the earth engine


Let the var t = [1,2,3,4,5,6,7,8,9]. I want to sum up the first 5 values in the list and print the number. I want the number 15.


Solution

  • For this you can:

    var t = ee.List([1,2,3,4,5,6,7,8,9]);
    var t2 = t.slice(0,5);
    print(t2.reduce(ee.Reducer.sum()));
    

    hope it helps,