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
  • 21,535
  • 7
  • 47
  • 56
JK2018
  • 429
  • 1
  • 9
  • 23

0 Answers0