Very Basic Question on Array and if xx in yy

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
hellotherenjny
Posts: 8
Joined: 17 Oct 2021, 10:49

Very Basic Question on Array and if xx in yy

17 Oct 2021, 10:54

Hello,

Thanks for all the help! I leaned a lot through this forum.

I'm a newbie learning coding for the first time so the question is very basic but I couldn't find an answer from the forum.

I'm simply trying to have a message box to say "Done" when "b" is in the array.

Can you help figure this out?

I must be completely missing something...

Thanks for the help!

Code: Select all

	Array := ["a", "b", "c"]
		
	If b in Array
	{
		msgbox, Done
	}
	else
	{
		msgbox, NOTDone
	}
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Very Basic Question on Array and if xx in yy

17 Oct 2021, 11:17

Code: Select all

Array := ["a", "b", "c"]
Loop, % Array.Length()	{
	if( Array[ A_index ] = "b" )
		Msgbox, "B" is in the array
}

Or perhaps...

Code: Select all

Index := 0
Object := { A: ++Index , B: ++Index , C: ++Index }

if( object.HasKey("B") )
	Msgbox, "B" is in the object

One more for good measure.

Code: Select all

Array := ["a", "b", "c"]
for k, v in Array		{
	if( v = "b" )
		Msgbox, "B" is in the array
}
User avatar
Chunjee
Posts: 1418
Joined: 18 Apr 2014, 19:05
Contact:

Re: Very Basic Question on Array and if xx in yy

17 Oct 2021, 11:52

Perplexing I know but ahk does not come with an .includes or .indexOf method.

You may add them with array.ahk
https://chunjee.github.io/array.ahk/#/docs?id=includes
https://chunjee.github.io/array.ahk/#/docs?id=indexof

Code: Select all

; requires https://www.npmjs.com/package/array.ahk
Array := ["a", "b", "c"]

if (Array.includes("b")) {
	msgbox, done
}

Array.includes("z")
; => false

Array.indexOf("b")
; => 2
hellotherenjny
Posts: 8
Joined: 17 Oct 2021, 10:49

Re: Very Basic Question on Array and if xx in yy

17 Oct 2021, 19:57

Hellbent & Chunjee - This is super helpful and it works now! Most importantly your notes helped me understand the concept behind array.

You guys are awesome! I really appreciate it!!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput and 115 guests