I want to do something like:

var from = [2,3]
var to = Array(from.length).fill(1)

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?

| improve this question | | | | |
  • 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 '19 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 '19 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 '19 at 11:04
  • @RodrigoE.Principe I believe that the code editor is based on Caja, based on some odd errors that I could find in the source code of Caja. This limits the code-editor to ES5 strict mode with little hope to ever be updated. Reminder to myself to not start anything important in the code editor. – Andrei May 12 at 17:40

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)
| improve this answer | | | | |
  • 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 '19 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 '19 at 4:30
  • the code editor is based on Caja, isn't it? That would make it ES5 – Andrei May 12 at 17:36
  • 1
    ui.Select is a client-side thing. You can't use a server-side object there without getting it from the server using evaluate() or getInfo() (use evaluate if you can). – Noel Gorelick May 13 at 18:14
  • And yes, the code editor is Caja, ES5. – Noel Gorelick May 13 at 18:15

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.