EN
TypeScript - 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 TypeScript.
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: string = 'This is example text...';
2
3
const result: boolean = text.includes('example');
4
5
console.log(result); // true
xxxxxxxxxx
1
// ONLINE-RUNNER:browser;
2
3
const text: string = 'This is example text...';
4
5
const result: boolean = text.includes('xyz');
6
7
console.log(result); // false