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: 1-js/05-data-types/03-string/article.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -140,7 +140,7 @@ alert( str.charAt(0) ); // П
140
140
141
141
// останній символ
142
142
alert( str[str.length - 1] ); // т
143
-
alert( str.at(-1) );
143
+
alert( str.at(-1) ); // т
144
144
```
145
145
146
146
Як бачите, перевага методу `.at(pos)` полягає в тому, що він допускає від'ємну позицію. Якщо `pos` від'ємне число, тоді позиція відраховується з кінця рядка.
@@ -174,7 +174,7 @@ for (let char of "Привіт") {
174
174
let str ='Ой';
175
175
176
176
str[0] ='о'; // помилка
177
-
alert( str[0] ); // не працює
177
+
alert( str[0] ); // не працює, тому що у попередньому рядку помилка
178
178
```
179
179
180
180
Можна створити новий рядок замість старого, записавши його в ту саму змінну.
0 commit comments