@mirei/ts-collections
    Preparing search index...

    Function any

    • Determines whether the sequence contains at least one element that matches the optional predicate.

      Type Parameters

      • TElement

        Type of elements within the source iterable.

      Parameters

      • source: Iterable<TElement>

        The source iterable.

      • Optionalpredicate: Predicate<TElement>

        Optional function used to test elements. When omitted, the function returns true if source contains any element.

      Returns boolean

      true when a matching element is found; otherwise, false.

      When the predicate is omitted, only the first element is inspected, making this more efficient than count(source) > 0.

      const numbers = [1, 2, 3, 4, 5];
      const hasEvenNumber = any(numbers, x => x % 2 === 0);
      console.log(hasEvenNumber); // true

      const oddNumbers = [1, 3, 5];
      const hasEvenNumber2 = any(oddNumbers, x => x % 2 === 0);
      console.log(hasEvenNumber2); // false