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

Transform an tab of key values into an array of key values

I would like to transform an tab array of key values into an array of key values

     rates.map(rate => {
       return {
         [rate]: account.vent.filter(v => v.rate === rate)[0]
           ?.vat,
       }
     })


(5) [{…}, {…}, {…}, {…}, {…}]
0: {10: 500}
1: {20: 630}
2: {5: undefined}
3: {19.6: undefined}
4: {1: undefined}

I have this in my console I would like something more like:

{
  10: 500
  20: 630
  5: undefined
  19.6: undefined
  1: undefined
}

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

>Solution :

Add this and your problems will be solved

.reduce(function(p,c){
    return {...p,...c};
},{})

Your code will look like this after adding the above code

rates.map(rate => {
       return {
         [rate]: account.vent.filter(v => v.rate === rate)[0]
           ?.vat,
       }
     })
.reduce(function(p,c){
    return {...p,...c};
},{})
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