I tried the function below which was posted by Nicolas Gauthier via Stack Overflow to get a function from a string by naming it, and when used with the name of a variable, it returns the variable's value.
It copes with dotted variable names (values of an object). It works with global variables and variables declared with var, but NOT with variables defined with 'let' which are not visible in called functions.
/***
* getFunctionFromString - Get function from string
*
* works with or without scopes
*
* @param string string name of function
* @return function by that name if it exists
* @author by Nicolas Gauthier via Stack Overflow
***/
window.getFunctionFromString = function(string)
{
let scope = window; let x=parent;
let scopeSplit = string.split('.');
let i;
for (i = 0; i < scopeSplit.length - 1; i++)
{
scope = scope[scopeSplit[i]];
if (scope == undefined) return;
}
return scope[scopeSplit[scopeSplit.length - 1]];
}