Deleting Key from Object based on key's existence in another Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Yogi
Posts: 12
Joined: 06 Jul 2022, 23:03

Deleting Key from Object based on key's existence in another  Topic is solved

23 Aug 2022, 19:47

Hi there, in this example there are two objects:

Code: Select all

Reference := {"5C" : {"b" : "Banana" , "p" : "Pear"}} 

Code: Select all

testing := {"1a" : {"a" : "Apple" , "b" : "Banana" , "p" : "Pear"}  , "2" :  {"d" : "Dog" , "e" : "Elephant" , "f" : "Frog"}  , "3" :  {"g" : "Goat" , "h" : "Helicopter" , "i" : "Indigo"}}
I want to delete keys from testing.1a if they exist in Reference.5C

Using:

Code: Select all

for k in testing.1a
{
    if reference.5C[k] != ""
        testing.1a.Delete(k)
}
The output is:

Code: Select all

{"1a": {"a": "Apple", "p": "Pear"}, "2": {"d": "Dog", "e": "Elephant", "f": "Frog"}, "3": {"g": "Goat", "h": "Helicopter", "i": "Indigo"}}
It has deleted the key "b" and it's pair value "Banana" but "p" remains. I can't understand why.

---------
Edit:

Solved by cloning the object here:

Code: Select all

for k in testing.1a.Clone()
{
    if reference.5C[k] != ""
        testing.1a.Delete(k)
}
It doesn't seem to like deleting from the same object it's looping.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot] and 176 guests