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

How to convert Object in Array

I have a object and I can try to convert this object in a special array,

This is the index
const index = 3

This is my object
object = { fruit: apple vegetable: carrot number: 5 color: red }

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

This is the array structure that I want to achieve
[ 3: { fruit: apple vegetable: carrot number: 5 color: red } ]

I´m not expert in arrays but I try this and dont´t convert in array with the special structure

this.object.entries(newObj).map(x => { return index[x] })

Please could you help me, I would really appreciate your help.

>Solution :

Generate a new array with required length and assign the object to required index

const index = 3
const myObject = { fruit: 'apple', vegetable: 'carrot', number: 5, color: 'red' }
const op = new Array(index + 1);
op[index] = myObject;
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