append one array to another

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
whitigerqn
Posts: 3
Joined: 02 Oct 2018, 08:59

append one array to another

20 Jun 2019, 15:18

Hi,
I'm trying to simply combine two arrays, and the Push method makes it seem like this should be pretty easy. I know I could loop through the second array and simply assign each key:value pair to the first array, but I'd like to understand how to use the Push method better.

Why does this not work?

Code: Select all

array1 := { a:"red", b:"blue" }
array2 := {c:"yellow", d:"green"}

array1.push(array2)
Thanks for any help!
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: append one array to another

20 Jun 2019, 15:27

Try this to see a working case of Push():

Code: Select all

array1 := ["red", "blue"]
array2 := ["yellow", "green"]

array1.push(array2*)
I hope that helps.

Push() will not work as intended for associative arrays.
User avatar
Hellbent
Posts: 2112
Joined: 23 Sep 2017, 13:34

Re: append one array to another

20 Jun 2019, 15:35

Try this.

Code: Select all


array1 := { a:"red", b:"blue" }
array2 := {c:"yellow", d:"green"}

for k, v in array2	{
	array1[k]:=v
}

for k,v in Array1
	msgbox,% k "`n" v

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], peter_ahk and 131 guests