You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 09-Data-Structure-Modern-Operators-and-Strings/README.md
+51-2Lines changed: 51 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -661,7 +661,7 @@ console.log(airline.indexOf("Codo")); // output -1 (since result is not found)
661
661
662
662
### Slice Method
663
663
664
-
The `slice()` method returns a shallow copy of a portion of an arrayl or string into a new array object selected from `start` to `end`
664
+
The `slice()` method returns a shallow copy of a portion of an array or string into a new array object selected from `start` to `end`
665
665
666
666
Syntax
667
667
@@ -676,6 +676,7 @@ The importance of using these indexes is using the `slice()` method to get `inde
676
676
**Start**
677
677
678
678
```js
679
+
constairplane="Dana Air Nigeria";
679
680
console.log(airplane.slice(5));
680
681
```
681
682
@@ -859,7 +860,54 @@ const capitalizeName = function (name) {
859
860
};
860
861
```
861
862
862
-
## Summary
863
+
### Padding
864
+
865
+
This allows us to add a number of elements to a string until a string is at a desired length.
866
+
867
+
```js
868
+
constmessage="Go to gate 23!";
869
+
console.log(message.padStart(25, "+")); // +++++++++++Go to gate 23!
870
+
```
871
+
872
+
This will add 11 plus symbols to the beginning of the string because using the `padStart()` method, we specified the string to be 25 characters long including the symbol and since the string `"Go to gate 23"` is 14 characters, the `padStart` method will fill it up with 11 + symbols.
873
+
874
+
If the string we want to pad is the same number of chracters on `padStart()` method, no value will be added to the string.
875
+
876
+
For example:
877
+
878
+
```js
879
+
constmessage="Hey";
880
+
console.log(message.padStart(3, "+")); // Hey
881
+
```
882
+
883
+
We also have the `padEnd()` method, which is the opposite of `padStart()`
884
+
885
+
Let's add 1 plus symbol at the end and beginning of a string.
console.log(`There are ${n} planes in line ${"✈️".repeat(n)}`);
903
+
}
904
+
905
+
planesInline(10); // There are 10 planes in line ✈️✈️✈️✈️✈️✈️✈️✈️✈️✈️
906
+
planesInline(3); // There are 3 planes in line ✈️✈️✈️
907
+
planesInline(5); // There are 5 planes in line ✈️✈️✈️✈️✈️
908
+
```
909
+
910
+
## Summary of the String Methods
863
911
864
912
- `toLowerCase()`: Converts all the alphabetic characters in a string to lowercase.
865
913
- `toUpperCase()`: Converts all the alphabetic characters in a string to uppercase.
@@ -873,3 +921,4 @@ const capitalizeName = function (name) {
873
921
- `endsWith()`: Returns true if the sequence of elements of searchString converted to a String is the same as the corresponding elements of this object (converted to a String) starting at endPosition – length(this). Otherwise returns false.
874
922
- `padStart`: Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length. The padding is applied from the start (left) of the current string.
875
923
- `padEnd`: Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length. The padding is applied from the end (right) of the current string.
924
+
- `repeat()`: The repeat() method constructs and returns a new string which contains the specified number of copies of the string on which it was called, concatenated together.
0 commit comments