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

171
Views
javascript looping over data and recreating a data structure

If I have data like this:

{
"zone_temps" : {
   "VAV1": "read 12345:2 analogInput 2",
   "VAV2": "read 12345:2 analogInput 1",
   "VAV3": "read 12345:2 analogInput 1",
   "VAV4": "read 12345:2 analogInput 2",
   "VAV5": "read 12345:2 analogInput 1",
   "VAV6": "read 12345:2 analogInput 2",
   "VAV7": "read 12345:2 analogInput 1",   
   "VAV8": "read 12345:2 analogInput 1",   
   "VAV9": "read 12345:2 analogInput 2",   
   "VAV10": "read 12345:2 analogInput 1"}
}

Could someone give me a tip what a javascript function would look like looping over the data and recreating the data structure with same keys but the values would be in integer made from math.random()

Hopefully that makes sense, looking for a final output like this:

{
"zone_temps" : {
   "VAV1": "66",
   "VAV2": "88",
   "VAV3": "55",
   "VAV4": "66",
   "VAV5": "77",
   "VAV6": "67",
   "VAV7": "79",   
   "VAV8": "87",   
   "VAV9": "75",   
   "VAV10": "71"}
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The English in the question is almost the answer in JS: Loop over the keys (map()) producing key-value pairs with random (Math.random()) values. Object.fromEntries() combines those pairs into a new object

const temps = {
  "VAV1": "read 12345:2 analogInput 2",
  "VAV2": "read 12345:2 analogInput 1",
  "VAV3": "read 12345:2 analogInput 1",
  "VAV4": "read 12345:2 analogInput 2",
  "VAV5": "read 12345:2 analogInput 1",
  "VAV6": "read 12345:2 analogInput 2",
  "VAV7": "read 12345:2 analogInput 1",
  "VAV8": "read 12345:2 analogInput 1",
  "VAV9": "read 12345:2 analogInput 2",
  "VAV10": "read 12345:2 analogInput 1"
}

const result = Object.fromEntries(Object.keys(temps).map(key => {
  return [ key, Math.round(Math.random()*100) ]
}))

console.log(result)

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!