mardi 30 mars 2021

Filter keys and values from a randomly sorted object in JavaScript

I've got these three objects and I was wondering how I would filter the numeric values and get an output like: RMB = 79.76 (for the first object), RUB = 94.83 (for the first string) and RLB = 64.57 (for the first object).

The main problem is that the keys (Real Lower Band, Real Middle Band and Real Lower Band) are swapped sometimes and their order is random. I suppose this could be done with regex but I'm not very sure how to solve this.

Any help would be greatly appreciated!

Objects:

object1 = {Real Middle Band=79.76, Real Upper Band=94.83, Real Lower Band=64.57}
object2 = {Real Upper Band=96.85, Real Lower Band=62.02, Real Middle Band=84.90}
object3 = {Real Lower Band=42.85, Real Upper Band=65.01, Real Middle Band=55.60}

Desired output

//for each object...
RMB = 79.76
RUB = 94.83
RLB = 64.57



Aucun commentaire:

Enregistrer un commentaire