Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

169
Vistas
Get automated names for JS object keys

I'm building a JS script in GoogleEarthEngine. I am automating the code for many year to get a vegetation index (Enhanced Vegetation Index (EVI)) for each year. The code I'm working itself is much more complex, that's why I just added one here for this question.(code here).

I'm trying to get the name of the layer in the key of the JS Object. So it would be:

buffer_size: 500
class: 0
EVI_2021_mean: MEAN_VALUE_FOR_THIS_YEAR

and have in the end, other columns following the same idea, only changing the year value in the Key of the object and its mean value for the Value of the object

The format itself is important to be that way so I can export to KML it afterwards and move on with further analysis.

Instead, what I'm getting is the string 'key' as the Key and the string EVI_2021_mean as the Value.

features: List (4 elements)
0: Feature 0 (Polygon, 3 properties)
type: Feature
id: 1
geometry: Polygon, 24 vertices
properties: Object (3 properties)
    buffer_size: 500
    class: 0
    key: EVI_2021_mean

Obs: I'm setting the mean value inside the GetMean function:

var GetMean = function (fc, img, nome_img) {
  print(nome_img);
  
  var dict = [];
  var ZS_mean =  img.reduceRegion({
    reducer: ee.Reducer.mean()
    ,geometry: POI
    ,scale: 30
  });
  dict.push({
    key:   nome_img+'_'+'mean',
    value: ZS_mean.constant
  });
  print(ZS_mean);

  var SetMean = function(f) {
    return f.set(dict[0]);
  };
  
  return POI.map(SetMean);
};
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can set dynamic keys for JavaScript objects using the following notation:

const myKey = 'someKey'
const myObj = {
    [myKey]: 'myValue'
}

console.log(myObj)  // => { someKey: 'myValue' }

Additionally, you can set a dynamic property on an existing object like so:

const myKey = 'someKey'
const myObj = {}

myObj[myKey] = 'myValue'

console.log(myObj)  // => { someKey: 'myValue' }

I'd suggest modifying your code to make dict an object (like dict = {}) and where you dict.push({ ... }) to do like dict[nome_img+'_mean'] = ZS_mean.constant.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda