input value
search value
position at which to start searching for searchValue
(default: 0)
boolean indicating whether one value contains another
var bool = contains( 'last man standing', 'stand' );
// returns true
var bool = contains( [ 1, 2, 3, 4 ], 2 );
// returns true
var bool = contains( 'presidential election', 'president' );
// returns true
var bool = contains( [ NaN, 2, 3, 4 ], NaN );
// returns true
var bool = contains( 'javaScript', 'js' );
// returns false
var bool = contains( [ 1, 2, 3, {} ], {} );
// returns false
var bool = contains( 'Hidden Treasures', '' );
// returns true
Tests if an array-like value contains a search value.
Notes
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.val
is an array-like object, the function checks whether the input array contains an element strictly equal to the specified search value.String.prototype.includes
, part of the ECMAScript 6 specification. This function is different from a call toString.prototype.includes.call
insofar as type-checking is performed for all arguments.position < 0
, the search is performed for the entire input array or string.second argument must be a primitive string primitive when the first argument is a string