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

convert a simple javascript arary to a list of objects

So i’m trying to do something pretty simple.

I have an array that looks like this

l = [0.5, 4.5, 7.5]

I want to convert it to the following array of objects

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

obj = [
  {value: 0.5, width:2},
  {value: 4.5, width:2},
  {value: 7.5, width:2}
]

I seem to keep tripping up on this. Any help would be much appreciated. thanks

>Solution :

Something like this?

const numbers = [ 0.5, 4.5, 7.5 ];
const objects = numbers.map( n => ({ value: n, width: 2 });
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