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

234
Views
Key value pairs array into array object
pops = [
    [
      {
        key: 'test1',
        value: '0'
      }
    ],
    [
      {
        key: 'test2',
        value: '0'
      },
      {
        key: 'test3',
        value: '0'
      }
    ]
  ];

need to convert into this format

formated =
[{
 'test1':'0',
},
{
 'test2':'0',
 'test3':'0'
}]

I tried to solve the problem with this code but had no luck. can anyone help me to solve this problem? Thank you.

let formated = []
let count=0
for(let item of this.pops){
 
  for(let prop of item){
   formated[count].push(prop.key:prop.value)
  }
  count++;
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

This can be achieved with a combination of map and reduce:

const pops = [
    [
      {
        key: 'test1',
        value: '0'
      }
    ],
    [
      {
        key: 'test2',
        value: '0'
      },
      {
        key: 'test3',
        value: '0'
      }
    ]
  ];
  
const formatted = pops.map(i =>  i.reduce( (acc,x) => ({...acc,[x.key]:x.value}),{}));

console.log(formatted);

over 4 years ago · Santiago Trujillo 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!