We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 32b59c3 commit 937f45cCopy full SHA for 937f45c
1 file changed
javascript/5_string-programs/deleteFirstChar.js
@@ -0,0 +1,32 @@
1
+// 9. Delete First Character of a String
2
+
3
+// The slice() method is frequently used to remove the first character by returning a new string from index 1 to the end.
4
+{
5
+ let s1 = "hihello";
6
+ let s2 = s1.slice(1);
7
+ console.log(s2);
8
+}
9
10
+//Similar to slice(), substring() creates a new string starting from index 1, effectively removing the first character.
11
12
13
+ let str = "hihello";
14
+ let newStr = str.substring(1);
15
+ console.log(newStr);
16
17
18
+// Using Array Destructuring with join()
19
20
21
22
+ let s2 = [...s1].slice(1).join("");
23
24
25
26
+// Using replace() with Regular Expression
27
28
29
30
+ let s2 = s1.replace(/^./, "");
31
32
0 commit comments