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

Object.entries splitting function strangely?

I have an object like this:

{
 'icon':'info',
 'size':'small',
 'content':'label'
}

I’m trying to split it up into an array of new objects where there is one property per object:

{'icon':'info'}, {'size':'small'} , {content':'label}

I thought I could do this using Object.entries like this:

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

Object.entries(controlsObject).map(prop => ({ prop }))

But it’s really not working out for me – is there another way? Where am I going wrong?

>Solution :

You should instead do this:

Object.entries(controlsObject).map(([key, value]) => ({ [key]: value }))
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