I have following code:
ignored := [ "Rainmeter.exe", "Nimi Places.exe", "mumble.exe" ]
a := ignored.HasKey("mumble.exe")
MsgBox,,, %a%
It returns 0
even though the string is clearly present in the array.
How do I test if a string value is present in an array?
PS: I also tried if var in
which gives same results.
You can use the includes() method in JavaScript to check if an item exists in an array. You can also use it to check if a substring exists within a string. It returns true if the item is found in the array/string and false if the item doesn't exist.
The includes() method returns true if an array contains a specified value. The includes() method returns false if the value is not found.
To check if a value is an array of specific type in TypeScript: Use the Array. isArray() method to check if the value is an array. Iterate over the array and check if each value is of the specific type.
To check if an array contains a specific element in C#, call Array. Exists() method and pass the array and the predicate that the element is specified element as arguments. If the element is present in the array, Array. Exists() returns true, else it returns false.
You can't, using just one command. Such functionality is not implemented in AHK_L as of 1.1.22.3.
You'll have to either define your own function
hasValue(haystack, needle) {
if(!isObject(haystack))
return false
if(haystack.Length()==0)
return false
for k,v in haystack
if(v==needle)
return true
return false
}
or use some fancy workaround:
ignored := { "Rainmeter.exe":0, "Nimi Places.exe":0, "mumble.exe":0 }
msgbox, % ignored.HasKey("mumble.exe")
This would create an associative array and put your values as keys (the values are set to 0 here), so the .HasKey()
makes sense to use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With