Skip to content

Commit adcfca6

Browse files
string#accessing-characters
1 parent 82285a9 commit adcfca6

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

1-js/05-data-types/03-string/article.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,37 +140,37 @@ Zdarza się, że osoby z praktyką w innych językach przypadkowo dodają nawias
140140
Należy pamiętać, że `str.length` jest właściwością numeryczną, a nie funkcją. Nie ma potrzeby dodawania po nim nawiasu.
141141
```
142142
143-
## Accessing characters
143+
## Dostęp do znaków
144144
145-
To get a character at position `pos`, use square brackets `[pos]` or call the method [str.charAt(pos)](mdn:js/String/charAt). The first character starts from the zero position:
145+
Aby uzyskać znak w pozycji `pos`, użyj nawiasów kwadratowych `[pos]` lub wywołaj metodę [str.charAt(pos)](https://developer.mozilla.org/pl/docs/Web/JavaScript/Reference/Global_Objects/String/charAt). Pierwszy znak zaczyna się od pozycji zerowej:
146146
147147
```js run
148148
let str = `Hello`;
149149
150-
// the first character
150+
// zwraca pierwszy znak
151151
alert( str[0] ); // H
152152
alert( str.charAt(0) ); // H
153153
154-
// the last character
154+
// zwraca ostatni znak
155155
alert( str[str.length - 1] ); // o
156156
```
157157

158-
The square brackets are a modern way of getting a character, while `charAt` exists mostly for historical reasons.
158+
Nawiasy kwadratowe to nowoczesny sposób na uzyskanie znaku, natomiast `charAt` istnieje głównie ze względów historycznych.
159159

160-
The only difference between them is that if no character is found, `[]` returns `undefined`, and `charAt` returns an empty string:
160+
Jedyna różnica między nimi polega na tym, że jeśli nie zostanie znaleziony żaden znak, `[]` zwraca `undefined`, a `charAt` zwraca pusty ciąg:
161161

162162
```js run
163163
let str = `Hello`;
164164

165165
alert( str[1000] ); // undefined
166-
alert( str.charAt(1000) ); // '' (an empty string)
166+
alert( str.charAt(1000) ); // '' (pusty ciąg)
167167
```
168168

169-
We can also iterate over characters using `for..of`:
169+
Możemy również iterować po znakach, używając `for..of`:
170170

171171
```js run
172172
for (let char of "Hello") {
173-
alert(char); // H,e,l,l,o (char becomes "H", then "e", then "l" etc)
173+
alert(char); // H,e,l,l,o (char - najpierw "H", później "e", następnie "l" itd.)
174174
}
175175
```
176176

0 commit comments

Comments
 (0)