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

130
Views
Merge objects in array of objects based on id

I have an array of objects like this How to achieve output form of this array ? Input:

[
 { meta_key: 'nickname', meta_value: 'testqa2', id: '10' },
  { meta_key: 'first_name', meta_value: 'TEST', id: '10' },
  { meta_key: 'last_name', meta_value: 'QA', id: '10' },
  { meta_key: 'nickname', meta_value: 'testqa10', id: '11' },
  { meta_key: 'first_name', meta_value: 'TEST', id: '11' },
  { meta_key: 'last_name', meta_value: 'QA', id: '11' }
]

Output

[
 {id:'10 , nickname:'testqa2 , first_name:'TEST' , last_name :'QA'},
 {id:'10 , nickname:'testqa10, first_name:'TEST' , last_name :'QA'}
]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you can do it using reduce like this

const data = [
 { meta_key: 'nickname', meta_value: 'testqa2', id: '10' },
  { meta_key: 'first_name', meta_value: 'TEST', id: '10' },
  { meta_key: 'last_name', meta_value: 'QA', id: '10' },
  { meta_key: 'nickname', meta_value: 'testqa10', id: '11' },
  { meta_key: 'first_name', meta_value: 'TEST', id: '11' },
  { meta_key: 'last_name', meta_value: 'QA', id: '11' }
]


const result = Object.values(data.reduce((res, {id, meta_key, meta_value}) => {
  return {
    ...res,
    [id]: {
      id,
      ...res[id],
      [meta_key]: meta_value
    }
  
  }

}, {}))

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!