Skip to content

Commit 079f4b7

Browse files
Add String_Methods.js with examples of string manipulation methods in JavaScript
1 parent 98b1446 commit 079f4b7

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

Example/String/String_Methods.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// String in JavaScript
2+
3+
// String is a built-in object in JavaScript that represents a sequence of characters.
4+
// Strings are immutable, meaning once created, they cannot be changed.
5+
// However, you can create new strings based on existing ones.
6+
// Strings can be created using single quotes, double quotes, or backticks (template literals).
7+
8+
data = "Codes With Pankaj";
9+
10+
// String Methods
11+
// 1. length
12+
console.log(data.length);
13+
14+
// 2. charAt
15+
console.log(data.charAt(6));
16+
17+
// 3. indexOf
18+
console.log(data.indexOf("Pankaj"));
19+
20+
// 4. lastIndexOf
21+
console.log(data.lastIndexOf("Pankaj"));
22+
23+
// 5. slice
24+
console.log(data.slice(0, 4)); // Codes
25+
26+
// 6. substring
27+
console.log(data.substring(0, 4)); // Codes
28+
29+
// 7. substr
30+
console.log(data.substr(0, 4)); // Codes
31+
32+
// 8. toUpperCase
33+
console.log(data.toUpperCase()); // CODES WITH PANKAJ
34+
35+
// 9. toLowerCase
36+
37+
console.log(data.toLowerCase()); // codes with pankaj
38+
39+
// 10. replace
40+
console.log(data.replace("Pankaj", "John")); // Codes With John
41+
42+
// 12. replaceAll
43+
44+
console.log(data.replaceAll("a", "John")); // Codes With John

0 commit comments

Comments
 (0)