Languages
[Edit]
EN

JavaScript - check if string includes a substring

0 points
Created by:
JoanneSenior
1070

In this article, we would like to show you how to check if a string includes a substring in JavaScript.

Quick solution:

'This is example text...'.includes('example');  // true

 

Practical example

In the below examples we check if the string contains a substring using includes() method.

// ONLINE-RUNNER:browser;

const text = 'This is example text...';

const result = text.includes('example');

console.log(result);  // true
// ONLINE-RUNNER:browser;

const text = 'This is example text...';

const result = text.includes('xyz');

console.log(result);  // false

References

Alternative titles

  1. JavaScript - check if string contains a substring
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join