array.findAll()

These functions searches the array for the specified object and return the positions of all occurrence of this values.

array.findAll( value_or_closure=any )

Returns: Array

Argument Description
value_or_closure
any, required
  • The value to find
  • A closure/function that gets every value of the array as input and returns true if the given value is right, with the following signature:

boolean function(el){}

Alias: object, value, closure, function, udf, callback

Examples

numbers = [ "one", "two", "three", "four", "one", "one", "two", "one" ];
	dump( numbers.findall( "one" ) ) ; // [ 1,5, 6, 8 ]
<span class="nv">fruits</span> <span class="o">=</span> <span class="p">[</span> <span class="s2">&quot;apple&quot;</span><span class="p">,</span> <span class="s2">&quot;orange&quot;</span><span class="p">,</span> <span class="s2">&quot;banana&quot;</span><span class="p">,</span> <span class="s2">&quot;orange&quot;</span><span class="p">,</span> <span class="s2">&quot;orange&quot;</span> <span class="p">];</span>
<span class="nf">dump</span><span class="p">(</span> <span class="nf">fruits.findall</span><span class="p">(</span> <span class="s2">&quot;orange&quot;</span> <span class="p">)</span> <span class="p">);</span> <span class="c">// [ 2, 4, 5 ]</span>
<span class="nv">notOranges</span> <span class="o">=</span> <span class="nf">arrayFindAll</span><span class="p">(</span> <span class="nv">fruits</span><span class="p">,</span>
	<span class="nf">function</span><span class="p">(</span> <span class="nv">el</span> <span class="p">){</span> 
		<span class="nv">return</span> <span class="nv">arguments.el</span> <span class="nv">neq</span> <span class="s1">&#39;oranges&#39;</span><span class="p">;</span>
<span class="p">});</span>
<span class="nf">dump</span><span class="p">(</span> <span class="nv">notOranges</span> <span class="p">);</span> <span class="c">// [ 1, 3 ]</span>

See also