0

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?

  • You are making 3 questions in one, I could answer the latter using GEE code. The first 2 questions can make one, and the latter a different one. – Rodrigo E. Principe Jan 8 at 19:38
  • @RodrigoE.Principe by now I am way more interested in the first questions, than the last, because I managed to solve the last by using this cumbersome solution stackoverflow.com/a/13735425. While doing this I also noticed that arrow => functions don't work in GEE JavaScript, probably for the same reason as fill – Andrei Jan 8 at 20:44
  • ok, you should edit your question then. I believe that the code editor is like a Sandbox, thus it has its own JS environment – Rodrigo E. Principe Jan 9 at 11:04
3

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)
  • Thanks! I don't know why, I somehow assumed that the argument of remap has to be an array, even though the documentation clearly says ee array. I guess I kind of have the feeling that very simple operations should be done on my side. In principle, should everything be done server side? Could you please expand your answer by saying if the sandboxed version complies with an older ES version, and with which, or is it its own GEE JavaScript? If the latter, could you point to a reference for the GEE flavour of JavaScript? I think many would find this useful. – Andrei Jan 9 at 15:52
  • You'll probably not notice this comment, but I'm trying my luck. I'm back to the same issue, but for ui.Select(ee.List.sequence(2000,2010,1)), an eeArray is not good enough, it really insists on an array with this error: The argument provided to ui.List.reset() must be an array. Any suggestion? – Andrei Feb 6 at 4:30

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.