此函数用于检查给定数组中是否有任何元素与条件匹配。您可以通过传递在给定数组的每个元素上运行的判断方法来检查这一点,并返回 true 或 false。
如果判断函数对于给定数组范围中的至少一个元素返回 true,则此函数返回 true。
Boolean (true if there is any element in the array for which the predicate returns true, false if there isn't any)
var _array =
[
"apple",
"banana",
"coconut",
"dragonfruit"
]
var _contains_apple = array_any(_array, function(_val, _ind)
{
return _val == "apple"
});
show_debug_message(_contains_apple); // prints 1 (true)
这将创建一个包含水果名称字符串的数组。我们希望检查该数组是否在任何位置包含 "apple"。
判断函数 _contains_apple 检查 _val == "apple" 并返回结果。当数组的任何一个元素为 true 时,array_any 将返回 true。