File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments