On any modern website there are a lot of global variables of complex configuration. Some are simple strings or dates, some will be objects or arrays.
I want to search for the string hello
to see if it is the value of any global variable, including nested properties/values.
For example, say this was a global variable:
nacho = {
"a" : "one",
"b" : [
{ "d" : "yes", "e" : "no" },
{ "d" : "alpha", "e" : "bravo" },
{ "d" : "hello", "e" : "bye" },
{ "d" : "charlie", "e" : "delta" },
],
"c" : "two"
}
Then searching for hello
should find nacho.b[2].d
;
2
Answers
Here is one way you can do that regarding your specific example:
https://playcode.io/1789958
Note: a stack snippet was not working due to it being a sandboxed environment, this is because we are referencing the window object.
-> You can try this Code :-