There is no general solution.
Objects do not have built-in knowledge about variable names outside the scope of which they were assigned.
If your variables are in the global scope (which they should not be), they are executed, but only by iterating over the keys in windowand searching for any values that match this.
FWIW (if you are not writing a JS debugger), if you think you need to know this, you are probably mistaken. For example, JS minifiers often change variable names, so you should not rely on them.
source
share