@@ -394,7 +394,7 @@ There are 3 methods in JavaScript to get a substring: `substring`, `substr` and
394
394
395
395
```js run
396
396
let str = "st*!*ringify*/!*";
397
- alert( str.slice(2) ); // ringify, from the 2nd position till the end
397
+ alert( str.slice(2) ); // ' ringify' , from the 2nd position till the end
398
398
```
399
399
400
400
Negative values for `start/end` are also possible. They mean the position is counted from the string end:
@@ -403,7 +403,7 @@ There are 3 methods in JavaScript to get a substring: `substring`, `substr` and
403
403
let str = "strin*!*gif*/!*y";
404
404
405
405
// start at the 4th position from the right, end at the 1st from the right
406
- alert( str.slice(-4, -1) ); // gif
406
+ alert( str.slice(-4, -1) ); // ' gif'
407
407
```
408
408
409
409
` str.substring(start [, end]) `
@@ -435,14 +435,14 @@ There are 3 methods in JavaScript to get a substring: `substring`, `substr` and
435
435
436
436
```js run
437
437
let str = "st*!*ring*/!*ify";
438
- alert( str.substr(2, 4) ); // ring, from the 2nd position get 4 characters
438
+ alert( str.substr(2, 4) ); // ' ring' , from the 2nd position get 4 characters
439
439
```
440
440
441
441
The first argument may be negative, to count from the end:
442
442
443
443
```js run
444
444
let str = "strin*!*gi*/!*fy";
445
- alert( str.substr(-4, 2) ); // gi , from the 4th position get 2 characters
445
+ alert( str.substr(-4, 2) ); // 'gi' , from the 4th position get 2 characters
446
446
```
447
447
448
448
Let's recap these methods to avoid any confusion:
0 commit comments