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

267
Vistas
How to make a value into a key?

So In my data I store it as shown on the first picture: enter image description here

What I wanna do is so when I fetch const SourceData = await db.query("SELECT value,time from weather_data where weather_id = 1");

I wanna turn it into an object that is time as key and value as value("time": value). So the object's first value would be "2018-06-05":12 for example. The reason I wanna do this is since I am planning on using this in a geojson so it becomes something like this (https://raw.githubusercontent.com/uber/react-map-gl/master/examples/.data/us-income.geojson) when I combine this new object with this one. enter image description here

If anyone have any better ideas please say, if not please tell me how I make the key into value the most efficient!

I am using Node.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can do this using reduce assuming sourceData is an array of objects with keys time and value:

const result = sourceData.reduce((acc, curr) => {
  acc[curr.time] = curr.value;
  return acc;
}, {})
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