I want to do something like:
var from = [2,3]
var to = Array(from.length).fill(1)
image.remap(from,to,0)
Of course, I could just assign [1,1]
to to
, but from is an input of a function and it is not guaranteed to have a length of 2.
The problem is that I get an error that says Array(...).fill is not a function
This suggests that the fill function is not supported, but I thought that the pure javascripts parts are interpreted in the browser's JavaScript engine, and only ee objects are sent to the Earth Engine. My browser definitely supports fill, as it works on its test page, so does anyone know why and how the code editor in Google Earth Engine does not support full Javascript? Also, does anyone know what JavaScript version is supported by Google Earth Engine's code editor? And lastly how can I actually create an array of variable length filled with 1 in Google Earth Engine's flavor of JavaScript?
Answer
You can't do it in client-side javascript (Rodrigo is correct in that it's a sandboxed environment for security reasons), but you can do it with a server-side function:
var to = ee.List.repeat(1, from.length)
No comments:
Post a Comment