Skip to content
Advertisement

How to print dict key value dynamically?

I’m trying to print a dict key value dynamically.

EX:

JavaScript

As we see the key ‘waninfo’ and ‘1’ are fixed and i would like to use the keys after dynamically, like this:

JavaScript

How can i do this?

Advertisement

Answer

If there’s a constant number of keys, it might be easiest to just declare separate variables for them:

JavaScript

If you have a variable (or very large) number of keys, use an iterable and then iterate over it to do the nested lookups:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement