-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
  • 7,779
  • 12
  • 46
  • 85

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.