Skip to content

Commit 07de969

Browse files
Merge pull request #14 from X-yn/patch-1
String.prototype.length is not a method
2 parents 0d9c81a + f972935 commit 07de969

File tree

1 file changed

+35
-19
lines changed

1 file changed

+35
-19
lines changed

ebook/05_additional_string_methods.md

+35-19
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,40 @@
22

33
There are many methods that we can use against strings. Here's a list of a few of them:
44

5-
```js
6-
// .length()
7-
const str = 'hello'
8-
str.length() // 5
9-
// .indexOf()
10-
const str2 = 'this is a short sentence'
11-
str2.indexOf('short'); // 10
12-
// slice()
13-
const str3 = 'pizza, orange, cereals'
14-
str3.slice(0,5) // 'pizza'
15-
// toUppercase() / toLowerCase()
16-
const str4 = 'lowercase'
17-
str4.toUpperCase(); // 'LOWERCASE'
18-
const str5 = 'UPPERCASE'
19-
str5.toLowerCase() // 'uppercase'
20-
```
21-
22-
There are many more methods, these were just a few as a reminder.
5+
1. **indexOf()**
6+
7+
Gets the position of the first occurence of the specified value in a string.
8+
```js
9+
const str = "this is a short sentence";
10+
str.indexOf("short");
11+
// Output: 10
12+
```
13+
2. **slice()**
14+
15+
Pulls a specified part of a string as a new string.
16+
```js
17+
const str = "pizza, orange, cereals"
18+
str.slice(0, 5);
19+
// Output: "pizza"
20+
```
21+
3. **toUpperCase()**
22+
23+
Turns all characters of a string to uppercase.
24+
```js
25+
const str = "i ate an apple"
26+
str.toUpperCase()
27+
// Output: "I ATE AN APPLE"
28+
```
29+
4. **toLowerCase()**
30+
31+
Turns all characters of a string to lowercase.
32+
```
33+
const str = "I ATE AN APPLE"
34+
str.toLowerCase()
35+
// Output: "i ate an apple"
36+
```
37+
38+
There are many more methods, these were just a few as a reminder. Check the [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#) for a more in-depth description on the above methods.
2339

2440
 
2541

@@ -112,4 +128,4 @@ As the name suggests, this new method will repeat what we pass in.
112128
let hello = "Hi";
113129
console.log(hello.repeat(10));
114130
// "HiHiHiHiHiHiHiHiHiHi"
115-
```
131+
```

0 commit comments

Comments
 (0)