Checks if a value exists in an array
Posted: 06 Sep 2016, 07:20
There are often used combine items into a single string instead of an array. You can check if a value exists in this "array" by searching in this string:
But it is not simple way check this in real array. Some examples from another language:
I make such function, but it is better have built-in method. Python method would be good.
Code: Select all
stringArray := item1 . item2 . item3
IfInString, x, stringArray
; Another workaround:
(x ~= "MyRegExp1|MyRegExp2|MyRegExp3")
; Another workaround:
(x=a || x=b || ... || x=z)
Code: Select all
; js method indexOf()
array.indexOf(var)
; php func in_array()
in_array(x, array)
; python
if 'a' in ['a','b','c']:
print "YES"
else:
print "NO"
Code: Select all
; Return array of keys if exist
HasValue(var, arr) {
arrOfKeys := {}
for key, value in arr
if (value == var)
arrOfKeys.Push(key)
return (arrOfKeys.Length() = 0) ? false : arrOfKeys
}
Previous try, only for 'simple' arrays