Function includes

  • Category

    Determines whether an iterable includes a certain element, returning true or false as appropriate. Strict equality (===) is used to compare elements.

    Time complexity: O(n)

    Space complexity: O(1)

    Type Parameters

    • T

    Parameters

    • iterable: Iterable<T>

      The iterable to take elements from

    • searchElement: T

      The element to search for

    Returns boolean

    true if any element is truthy, false otherwise

    Iterable

    includes([1, 2, 3], 2); // true
    
    includes([1, 2, 3], 4); // false