Suppose I have the string:
var string = "function";
With
window[string];
I can call a function with the name of “function”.
But, when I have:
var string2 = "function.method.weHaveTogoDeeper";
it should call
window["function"]["method"]["weHaveTogoDeeper"]
I can’t do:
window[string2]
in this case. I dont know the number of “.” in the string, so I need some kind of routine.
you can split the string across
.by using theString.splitmethod:In this examples,
methodswill be the array["function","method","weHaveTogoDeeper"]. You should now be able to do a simple iteration over this array, calling each function on the result of the previous one.Edit
The iteration I had in mind was something like this:
In your example,
resultshould now hold the same output as