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

176
Views
Cleanest way to convert this array into a single object?

Just looking for the cleanest way to turn the following array into the following object format. Thanks a lot

const item = [
  { address: '123 fake street' },
  { loan: 'no' },
  { property: 'no' }
]

const obj = {
    address: '123 fake street',
    loan: 'no',
    property: 'no'
}
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You can use Object.assign() and spread syntax to convert the array of objects into a single object.

const item = [
  { address: '123 fake street' },
  { loan: 'no' },
  { property: 'no' }
]

const obj = Object.assign({}, ...item);
console.log(obj);

about 4 years ago · Juan Pablo Isaza Report

0

Reduce and spread syntax would be one clean way to convert the array to an object.

const item = [
  { address: '123 fake street' },
  { loan: 'no' },
  { property: 'no' }
]

let obj = item.reduce((pre, cur)=>{
    return {...pre, ...cur};
}, {});
    
// Result: obj={address: '123 fake street', loan: 'no', property: 'no'}
about 4 years ago · Juan Pablo Isaza Report

0

Just use a simple for...of loop to iterate over the array, and Object.entries to extract the key/value. Then just update an empty object with that information

const item = [
  { address: '123 fake street' },
  { loan: 'no' },
  { property: 'no' }
];

const obj = {};

for (const el of item) {
  const [[key, value]] = Object.entries(el);
  obj[key] = value;
}

console.log(obj);

Additional documentation

  • Destructuring assignment
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!