Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

268
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda