String

String.prototype.includes

Determines whether one string may be found within another string, returning true or false

Syntax

JavaScript
string.includes(searchString, position?)

Parameters

ParameterTypeDescription
searchStringstringA string to be searched for
positionnumberPosition to begin searching from

Return Value

true if the search string is found, false otherwise

Examples

Basic Usage
const str = 'Hello World';
console.log(str.includes('World')); // true
console.log(str.includes('world')); // false
Practical Example
const url = 'https://example.com/api/users';
if (url.includes('/api/')) {
  console.log('API endpoint detected');
}
Advanced Usage
const sentence = 'The quick brown fox';
console.log(sentence.includes('quick', 5)); // false

Understanding String.prototype.includes

The String.prototype.includes method in JavaScript determines whether one string may be found within another string, returning true or false. It belongs to the String object and is one of the most widely used methods for working with string values in modern JavaScript and TypeScript applications.

The method signature is string.includes(searchString, position?). It accepts 2 parameters: searchString, position. When called, it returns true if the search string is found, false otherwise. Understanding when and how to use includes() helps you write more expressive, readable code.

Common use cases for String.prototype.includes include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like string-indexof, string-startswith, string-endswith, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for String.prototype.includes is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More String Methods

Other methods in the String object

Related Tools

More String Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.