We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b75fe89 commit 3915dd0Copy full SHA for 3915dd0
1 file changed
javascript/5_string-programs/checkSubString.js
@@ -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
20
21
22
+// Using Regular Expressions (RegExp)
23
24
25
26
+ let pat = /world/;
27
+ let res = pat.test(s);
28
29
30
0 commit comments