Skip to content
Advertisement

Javascript make object string keys enumerable

I have a class set up with string keys, like this:

JavaScript

The goal is to dynamically loop over the functions in an instance like this:

JavaScript

However, everything I have tried has only resulted in the keys id and data.

I can manually get the function and run it just fine:

JavaScript

But it does not show up in any dynamic enumeration I have tried.

Manually setting the enumeration also works:

JavaScript

But that defeats the purpose of doing it dynamically. Is there any way to either dynamically get the names of functions with string keys, or make every property enumerable?

Advertisement

Answer

JavaScript

gives you

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