JavaScript String includes() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Method

Definition

String.prototype.includes(searchString, position?) returns true if the substring is found, otherwise false. The search is case-sensitive and does not change the string (ES2015).

Pass the required arguments shown below. Check return values and browser support before you rely on the result.

Syntax

Call string.includes. Start with this line.

JavaScript
str.includes(searchString, position?)
CallWhat it does
str.includes(searchString, position?)Primary signature.
string.includes(...)Call with the arguments your case needs.

Built into JavaScript. Call includes(...) on a string (or String instance) — no import required.

Library declarations
JavaScript
str.includes(searchString, position?)

Parameters

ParameterDescription
searchStringRequired. Substring to find (not a RegExp)
positionOptional. Start index; default 0; negatives act like 0

Return Value

Return ValueDescription
*true or false

JavaScript Examples

Example 1 — Basic Substring Check

Ask whether a string contains another string. Matching is case-sensitive.

JavaScript
const text = "JavaScript is fun";

console.log(text.includes("Script"));  // true
console.log(text.includes("script"));  // false
console.log(text.includes("Python"));  // false
Try It Yourself

How It Works

  1. Pick the haystack. text is the string you search in.
  2. Exact match. "Script" appears inside → true.
  3. Case matters. "script" is different from "Script" → false.
  4. Missing text. "Python" is not present → false.

Example 2 — Optional Start Position

Start the search from a given index so earlier matches are ignored.

JavaScript
const text = "JavaScript is fun";

console.log(text.includes("Script", 4));  // true
console.log(text.includes("Script", 5));  // false
console.log(text.includes("fun", 10));    // true
Try It Yourself

How It Works

  1. Index 4 is the start of "Script". Searching from there still finds it.
  2. Index 5 skips the S. The remaining text no longer contains "Script".
  3. Later substrings work too. "fun" still matches when you start near the end.
  4. Negative positions. Values less than 0 are treated like 0.

Example 3 — includes() vs indexOf()

Use includes for yes/no checks; use indexOf when you need the position.

JavaScript
const text = "JavaScript is fun";

console.log(text.includes("Script"));     // true
console.log(text.indexOf("Script"));      // 4
console.log(text.includes("Python"));     // false
console.log(text.indexOf("Python"));      // -1

// Case-insensitive check:
console.log(text.toLowerCase().includes("javascript")); // true
Try It Yourself

How It Works

  1. Boolean first. includes is perfect for if (text.includes(...)).
  2. Index when needed. indexOf returns 4 or -1.
  3. Same search idea. Both look for a substring; they differ in return type.
  4. Ignore case carefully. Lower both sides before calling includes.

Browser & Runtime Support

String.prototype.includes() is part of ES2015 (ES6). It works in all modern browsers and Node.js versions in common use today.

✓ Baseline · ES2015

String.prototype.includes()

Supported in Chrome 41+, Firefox 40+, Safari 9+, Edge 12+, and Node.js 4+. Not available in Internet Explorer without a polyfill.

98% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
includes() Excellent

Bottom line: Safe for modern web apps and current Node LTS. For IE11, feature-detect with typeof String.prototype.includes === "function" or fall back to indexOf(sub) !== -1.

Frequently Asked Questions

String.prototype.includes(searchString, position?) returns true if searchString is found anywhere in the string (from the optional start position), otherwise false. The search is case-sensitive.
Yes. "Blue Whale".includes("blue") is false. Normalize both sides with toLowerCase() (or toLocaleLowerCase()) when you need a case-insensitive check.
No. If searchString is a RegExp, includes() throws TypeError. Use RegExp.test() or String.match() for pattern searches.
true for any string, including the empty string. An empty search string is treated as found.
includes() returns a boolean — ideal for if checks. indexOf() returns the first index, or -1 if missing — better when you need the position.
No. Strings are immutable. includes() only reads and returns true or false.

Next: indexOf()

Learn how to find the first index of a substring when a boolean is not enough.

indexOf() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful