Dealing with {}

Hi !

Trying to deal with objects... to learn...
I've been trying things in my matrix props.

For example, this in the props.onValue :

Object.entries(Dossiers).forEach(([k,v]) => 
getIndex(this) == v ? console.log('yep') : console.log('non non non...') )

That's ok.

But now, i don't understand why this doesn't work (that's not in props.onValue :wink: ):

  const Dossiers = 
{
  "Basses" : 0,
  "Bois" : 6,
  "Cordes" : 12,
  ...
  "Cuivres" : 33
}
    
  var K = Object.keys(Dossiers)
  var V = Object.values(Dossiers)
  
  V.forEach( (el,i) => props.label = $ == el ?  K[i] : 'pistes' )

All labels are set to 'pistes'.

What's wrong here ?

Thank you

forEach iterates overs all items in V and reassigns props.label every time, this means it will always end up assigning the result of the last iteration.

Ok, thank you.

Finally, i got where i wanted with this :slight_smile:

 var K = Object.keys(Dossiers)
 var I = Object.values(Dossiers).indexOf($)

props.label = Object.values(Dossiers).includes($) ? K[I] : 'pistes'