Why doesn't this say "3" like it even says in the Doc, but instead nothing?
Well, it actually says 3... here. But the docs say that you need an AHK version
1.1.29+... so it gotta be quite new. I wasn't even really aware that it was added recently.
By default, any existing key will be overwritten, if you assign something (new) to it. But you can check for existing keys with
Haskey():
Code: Select all
Arr := {Number1: 1, Number2: 2, Number3: 3}
Arr.Number1 := 4
for key, val in Arr
msgbox % key " : " val
if arr.Haskey("Number2")
msgbox stop. Number2 already exists
else
Arr.Number2 := 5
if arr.Haskey("Number4")
msgbox stop. Number 4 already exists
else
Arr.Number4 := 5
for key, val in Arr
msgbox % key " : " val
Not existing keys will be created, when you assign a value to a key.