Languages
[Edit]
EN

JavaScript - check if string includes a substring

0 points
Created by:
Dirask Community
6300

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

Quick solution:

'dirask is awesome!'.includes('awesome');  // true

 

Practical example

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

// ONLINE-RUNNER:browser;

const string = 'dirask is awesome!';

console.log(string.includes('awesome!'));
// ONLINE-RUNNER:browser;

const string = 'dirask is awesome!';

console.log(string.includes('awful'));

References

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