Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4be3465

Browse files
committed
Adding strings source code
1 parent 52bbab6 commit 4be3465

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

String/README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# String Methods in JavaScript
2+
3+
### charAt()
4+
```javascript
5+
const charAtIndex = "Hello".charAt(1); // Output: "e"
6+
```
7+
8+
### concat()
9+
```javascript
10+
const concatenated = "Hello".concat(" World"); // Output: "Hello World"
11+
```
12+
13+
### toUpperCase()
14+
```javascript
15+
const upperCaseString = "hello".toUpperCase(); // Output: "HELLO"
16+
```
17+
18+
### toLowerCase()
19+
```javascript
20+
const lowerCaseString = "HeLLo".toLowerCase(); // Output: "hello"
21+
```
22+
23+
### substring()
24+
```javascript
25+
const subString = "JavaScript".substring(4, 10); // Output: "Script"
26+
```
27+
28+
### replace()
29+
```javascript
30+
const replacedString = "Hello, name!".replace("name", "John"); // Output: "Hello, John!"
31+
```
32+
33+
### split()
34+
```javascript
35+
const splitArray = "apple,banana,grape".split(","); // Output: ["apple", "banana", "grape"]
36+
```
37+
38+
### indexOf()
39+
```javascript
40+
const index = "JavaScript".indexOf("Script"); // Output: 4
41+
```
42+
43+
### endsWith()
44+
```javascript
45+
const endsWithWorld = "Hello, world".endsWith("world"); // Output: true
46+
```
47+
48+
### startsWith()
49+
```javascript
50+
const startsWithHello = "Hello, world".startsWith("Hello"); // Output: true
51+
```
52+
53+
### includes()
54+
```javascript
55+
const includesWorld = "Hello, world".includes("world"); // Output: true
56+
```
57+
58+
### trim()
59+
```javascript
60+
const trimmedString = " Hello, world ".trim(); // Output: "Hello, world"
61+
```
62+
63+
## Practice Questions
64+
65+
- [Find the Index of the First Occurrence in a String](https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string/)
66+
- [Reverse String](https://leetcode.com/problems/reverse-string)
67+
- [Valid Anagram](https://leetcode.com/problems/valid-anagram)
68+
- [Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix)
69+
- [Merge Strings Alternately](https://leetcode.com/problems/merge-strings-alternately)
70+
- [Length of Last Word](https://leetcode.com/problems/length-of-last-word/)
71+
- [Valid Palindrome](https://leetcode.com/problems/valid-palindrome)
72+
- [String Compression](https://leetcode.com/problems/string-compression)
73+
- [Reverse Words in a String](https://leetcode.com/problems/reverse-words-in-a-string)
74+
- [Reverse Vowels of a String](https://leetcode.com/problems/reverse-vowels-of-a-string)

0 commit comments

Comments
 (0)