EN
JavaScript - check if string includes a substring
0 points
In this article, we would like to show you how to check if a string includes a substring in JavaScript.
Quick solution:
xxxxxxxxxx
1
'This is example text...'.includes('example'); // true
In the below examples we check if the string
contains a substring using includes()
method.
xxxxxxxxxx
1
const text = 'This is example text...';
2
3
const result = text.includes('example');
4
5
console.log(result); // true
xxxxxxxxxx
1
const text = 'This is example text...';
2
3
const result = text.includes('xyz');
4
5
console.log(result); // false