array-any-x

Like Array.some but does not skip holes.

Usage no npm install needed!

<script type="module">
  import arrayAnyX from 'https://cdn.skypack.dev/array-any-x';
</script>

README

Travis status Dependency status devDependency status npm version jsDelivr hits bettercodehub score Coverage Status

array-any-x

Tests whether some element passes the provided function.

module.exportsboolean

This method tests whether any element in the array passes the test implemented by the provided function.

Kind: Exported member
Returns: boolean - true if the callback function returns a truthy value for any array element; otherwise, false.
Throws:

  • TypeError If array is null or undefined.
  • TypeError If callBack is not a function.
Param Type Description
array array The array to iterate over.
callBack function Function to test for each element.
[thisArg] * Value to use as this when executing callback.

Example

import any from 'array-any-x';

function isBiggerThan10(element, index, array) {
  return element > 10;
}

console.log(any([2, 5, 8, 1, 4], isBiggerThan10)); // false
console.log(any([12, 5, 8, 1, 4], isBiggerThan10)); // true