-1

Let's say I have an object

const myArray = {
   a : "hello"
}

and I have a string with the same name of that object like

var type ="myArray";

when I do console.log(type);

output: myArray

but I want to out that object to the console which has the same name as the value of variable type. How should I do that? Thanks in advance

Dino
  • 6,957
  • 8
  • 35
  • 75

1 Answers1

0

If it's a global variable, it will be stored in window.

So, you can do something like console.log(window[type]) to access to value.