Skip to content

Commit 937f45c

Browse files
committed
deletefirstchar
1 parent 32b59c3 commit 937f45c

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
let s1 = "hihello";
22+
let s2 = [...s1].slice(1).join("");
23+
console.log(s2);
24+
}
25+
26+
// Using replace() with Regular Expression
27+
28+
{
29+
let s1 = "hihello";
30+
let s2 = s1.replace(/^./, "");
31+
console.log(s2);
32+
}

0 commit comments

Comments
 (0)