Skip to content

Commit 3915dd0

Browse files
committed
checkSubString.js
1 parent b75fe89 commit 3915dd0

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// 12. Check Whether a String Contains a Substring
2+
3+
// Using includes() - Most used and Simplest Method
4+
5+
{
6+
let s = "abcde";
7+
let res = s.includes("bcd");
8+
9+
console.log(res);
10+
}
11+
12+
// Using indexOf() - Gives Index of First Occurrence as well
13+
14+
{
15+
let s = "Hello, world!";
16+
let res = s.indexOf("world") !== -1;
17+
console.log(s.indexOf("world"));
18+
19+
console.log(res);
20+
}
21+
22+
// Using Regular Expressions (RegExp)
23+
24+
{
25+
let s = "Hello, world!";
26+
let pat = /world/;
27+
let res = pat.test(s);
28+
29+
console.log(res);
30+
}

0 commit comments

Comments
 (0)