-3

in JS I would like to use a variable value as a property in an object. for example:

    let myVar='toto';   
    let myObjet={
             toto:['1', '2','3'],
             tata: ['a','b','c']
    }
//I want to recover the array of toto property ['1', '2','3']

let myArray=myObjet.myVar

but myObjet.myVar does not work.

how to use the value of myVar?

  • 1
    [Search results for the tittle of your question](https://www.google.com/search?q=how+to+use+a+variable+value+as+a+property+in+an+JS+object+site:stackoverflow.com) – adiga Jun 26 '21 at 10:17

1 Answers1

1

you can enter the object like this:

console.log(myObjet[myVar])
DerHerrGammler
  • 324
  • 2
  • 9