0

Is it possible to access to an object based on a parameter on this function?

function fnc (num) {
  const obj1 = { whatever : "foo1"}
  const obj2 = { whatever : "foo2"}
  return console.log([`obj${num}`].whatever)
}

fnc(1) // Expected Result foo1 but got undefined

Also tried with same result

`obj${num}`.whatever

Any idea? Thank you!!

David
  • 208,112
  • 36
  • 198
  • 279
Ewejnog
  • 23
  • 4

0 Answers0