Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

265
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!