Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "assert/contains/docs/types/index.d"

Index

Functions

Functions

Export assignment contains

  • contains(val: ArrayLike<any>, searchValue: any, position?: undefined | number): boolean
  • Tests if an array-like value contains a search value.

    Notes

    • When val is a string, the function checks whether the characters of the search string are found in the input string. The search is case-sensitive.
    • When val is an array-like object, the function checks whether the input array contains an element strictly equal to the specified search value.
    • For strings, this function is modeled after String.prototype.includes, part of the ECMAScript 6 specification. This function is different from a call to String.prototype.includes.call insofar as type-checking is performed for all arguments.
    • The function does not distinguish between positive and negative zero.
    • If position < 0, the search is performed for the entire input array or string.
    throws

    second argument must be a primitive string primitive when the first argument is a string

    Parameters

    • val: ArrayLike<any>

      input value

    • searchValue: any

      search value

    • Optional position: undefined | number

      position at which to start searching for searchValue (default: 0)

    Returns boolean

    boolean indicating whether one value contains another

    Example

    var bool = contains( 'last man standing', 'stand' );
    // returns true

    Example

    var bool = contains( [ 1, 2, 3, 4 ], 2 );
    // returns true

    Example

    var bool = contains( 'presidential election', 'president' );
    // returns true

    Example

    var bool = contains( [ NaN, 2, 3, 4 ], NaN );
    // returns true

    Example

    var bool = contains( 'javaScript', 'js' );
    // returns false

    Example

    var bool = contains( [ 1, 2, 3, {} ], {} );
    // returns false

    Example

    var bool = contains( 'Hidden Treasures', '' );
    // returns true