如何求和地球引擎中数字列表中的前 5 个列表值

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

让 var t = [1,2,3,4,5,6,7,8,9]。 我想总结列表中的前 5 个值并打印数字。我想要数字 15.

为此你可以:

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()));

希望对您有所帮助,