Test whether at least one element in a collection is truthy.
var any = require( '@stdlib/utils/any' );
Tests whether at least one element in a collection
is truthy.
var arr = [ 0, 0, 0, 0, 1 ];
var bool = any( arr );
// returns true
If provided an empty collection
, the function returns false
.
var bool = any( [] );
// returns false
- A
collection
may be either anArray
,Typed Array
, or an array-likeObject
(excludingstrings
andfunctions
). - The function does not skip
undefined
elements and is thus not optimized for sparse collections.
var randu = require( '@stdlib/math/base/random/randu' );
var any = require( '@stdlib/utils/any' );
var bool;
var arr;
var i;
arr = new Array( 100 );
for ( i = 0; i < arr.length; i++ ) {
arr[ i ] = ( randu() > 0.95 );
}
bool = any( arr );
// returns <boolean>