Undefined variable

I need to iterate through an object and get to the sub-objects.
I am able to get list1 correctly (___grecaptcha_cfg.clients[0])
but list2 (___grecaptcha_cfg.clients[0].l) returns “undefined”

If I were to run “___grecaptcha_cfg.clients[0].l” via Dev Tools it returns an output, but via the code it returns “undefined”
The webpage is “https://www.freepik.com/profile/login

Here is my code:

let list0 = ___grecaptcha_cfg.clients
for (let item1 of Object.keys(list0)) 
    let list1 = ___grecaptcha_cfg.clients[item1]
    for (let item2 of Object.keys(list1)) 
        let list2 = ___grecaptcha_cfg.clients[item1].item2

does this have a property literally named item2?

1 Like

item2 is generated via the script. It is not Literal. I need to iterate through the object and subobjects to find the correct one. See script above. Thanks

you are using dot notation so it is accessing a variable literally named item2

1 Like

list1 is generated in a similar way and that resolves correctly. See screenshot in main post. If there is a different way to get list2 then what should I put in the code? Thanks

in one case you use dot notation, the other bracket notation -dot notation will access literally the variable with that name so you can’t use it with variables

1 Like

So how would one execute ___grecaptcha_cfg.clients[0].l where “l” is stored in a variable

with bracket notation like you did with item1

1 Like

If you are sugesting I use let list2 = ___grecaptcha_cfg.clients[item1].[item2] then it returns "Uncaught SyntaxError: Unexpected token ‘[’ "

that’s wrong syntax, you can’t put the dot before the opening square parenthesis

1 Like

Sorry, you are right. That worked :slight_smile:

awesome, good job!

Happy coding!

1 Like