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

331
Views
Why is this map for loop code not working?

Someone with experience should be able to understand the error with ease, but for me it is hard, I tried learning online about map and for loop but no luck understanding the error, can someone please help me.

let jsonVal = [["ID","Name","Age"],["212","David","38"],["213","Mike","42"]]

let newJsonVal = [] ​
 for (let i =1; i< jsonVal.length-1; i++) {
    ​let newObject ={}
     ​jsonVal[i].map((d,j) => { 
       ​newObject[jsonVal[0][j] = d]
      ​})
    newJsonVal.push(newObject);
     console.log(newJsonVal);
 }

The output should look something like this:

[
  {
    "ID": "212",
    "Name": "David",
    "Age": "38"
  },
  {
    "ID": "213",
    "Name": "Mike",
    "Age": "42"
  }
]

Thanks for your help in advance

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As the previous answer but this time with multiple objects:

let jsonVal = [["ID","Name","Age"],["212","David","38"],["213","Mike","42"]]
let [keys, ...objs] = jsonVal;
let newJsonVal = []
objs.map((obj, i)=>{
    const newObj = keys.map((key, i)=>[key, obj[i]]);
    newJsonVal.push(Object.fromEntries(newObj));
})
console.log(newJsonVal)

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!