ArraySome()

This function calls a given closure/function with every element in a given array and returns true, if one of the closure calls returns true.

ArraySome( array=array, closure=function, parallel=boolean, maxThreads=number );

Returns: Boolean

Argument Description Default
array
array, required

array to iterate

Alias: object

closure
function, required

function/closure that implements the following constructor [function(any value[, numeric index,array array]):boolean].

Alias: function, callback, udf

parallel
boolean, optional

execute closures parallel

maxThreads
number, optional

maximum number of threads executed, ignored when argument "parallel" is set to false

Alias: maxThreadCount

20

Examples

uses a closure to determine if an item or expression exists

newArray = ['a','b','c','b','d','b','e','f'];
	dump(newArray);
<span class="nv">hasSome1</span> <span class="o">=</span> <span class="nf">arraySome</span><span class="p">(</span><span class="nv">newArray</span><span class="p">,</span><span class="nf">function</span><span class="p">(</span><span class="nv">item</span><span class="p">,</span><span class="nv">idx</span><span class="p">,</span><span class="nv">arr</span><span class="p">){</span>
    <span class="nv">return</span> <span class="nv">item</span> <span class="o">==</span> <span class="s1">&#39;b&#39;</span><span class="p">;</span>
<span class="p">});</span>
<span class="nf">dump</span><span class="p">(</span><span class="nv">hasSome1</span><span class="p">);</span>
<span class="c">// member function</span>
<span class="nv">hasSome2</span> <span class="o">=</span> <span class="nf">newArray.some</span><span class="p">(</span><span class="nf">function</span><span class="p">(</span><span class="nv">item</span><span class="p">,</span><span class="nv">idx</span><span class="p">,</span><span class="nv">arr</span><span class="p">){</span>
    <span class="nv">return</span> <span class="nv">item</span> <span class="o">==</span> <span class="s1">&#39;k&#39;</span><span class="p">;</span>
<span class="p">});</span>
<span class="nf">dump</span><span class="p">(</span><span class="nv">hasSome2</span><span class="p">);</span>

See also