SnipBits

How to test if a string includes a substring in Javascript

There is too many ways to check if a Javascript string contains a substring. Its nowadays one of the most common tasks in any Programming Language

The most simple one, is using the includes() method on a string

"this is a string".includes("string"); //true

based on caniuse.com the includes() function is supported by all browsers except Internet Explorer.

ìncludes() can accept a second paramater, an Integer which Indicates the Position where to start searching for


Maher Gallaoui

You like our Content? Follow us to stay up-to-date.