Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

String.prototype.includes

Checks whether a string contains a given substring.

Available since: ES2015

Syntax

str.includes(searchString, position)

Parameters

ParameterTypeDescription
searchStringstringThe substring to look for.
positionnumberOptional. The position to start searching from; defaults to 0.

Return value

boolean`true` if the substring is found, `false` otherwise.

Examples

A match and no match:

console.log('Hello, world'.includes('world'));
console.log('Hello, world'.includes('JS'));

Output:

true
false

The search is case-sensitive:

console.log('Hello'.includes('hello'));

Output:

false

Notes

To search case-insensitively, convert both strings to the same case with toLowerCase().

See also

Related recipes

In the tutorial

  • String methods — Useful string methods in JavaScript: finding a position, reading characters, padStart, repeat, split and join, method chains.

Thanks for reading!

Donate to the site — we work hard for you.