0

I have an object that has several attributes that have been dynamically generated with a loop. It has a structure similar to this :

const theObject = {
    "rank1": 23,
    "rank2": 43,
    "rank3": 21,
    "rank4": 29,
    "rank5": 25,
}

How can I dynamically get the value of a specific attribute in that object. for example if I wanted to console.log(theObject.rank2) but the "2" is dynamically generated from another object s id. How would I do that?

I tried something like console.log(theObject.rank+anotherObject.id) and I got undefined as result.

Andreas
  • 20,797
  • 7
  • 44
  • 55
JK2018
  • 237
  • 1
  • 2
  • 13

0 Answers0