Javascript properties and methods: String.prototype.includes()

Raphael Ugwu
2 min readJul 8, 2017
https://devdojo.com/course/javascript-basics/using-javascript

Trying to decide if a string may or may not be found within another string? The includes() method is perfect for this purpose, it checks for the presence of a string in another (longer) string, returning true if the string is found or false if otherwise.

SYNTAX: str.includes(searchString[, position])

PARAMETERS:

searchString : The string we are searching for within the larger string.

position: The position at which we begin to search for searchString. This position’s default value is 0. This parameter is optional when implementing the method.

Case Sensitivity: The includes() method is case sensitive. An expression such as the one below will return false .

A more detailed explanation on how to use this method would be:

In some cases, the include() method may not be available in all JavaScript implementations, do not fear! There is a quick workaround known as a polyfill (a browser fallback made in JavaScript that allows functionality you expect to work in modern browsers to work in older browsers):

polyfill for includes() method

Browser Compatibility: str.includes() is compatible with desktop browsers such as Chrome(41), Firefox(18–48), Edge, Opera and Safari. It is not compatible with Internet Explorer.

--

--