Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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'
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading