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?)
Call
What 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
Parameter
Description
searchString
Required. Substring to find (not a RegExp)
position
Optional. Start index; default 0; negatives act like 0
Return Value
Return Value
Description
*
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
Boolean first.includes is perfect for if (text.includes(...)).
Index when needed.indexOf returns 4 or -1.
Same search idea. Both look for a substring; they differ in return type.
Ignore case carefully. Lower both sides before calling includes.
Compatibility
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 ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · 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.