Skip to content

Commit 063c09e

Browse files
authored
More translation
Translate: "Strings are immutable", "Changing the case", and "Searching for a substring"
1 parent 1a7e2cf commit 063c09e

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

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

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ for (let char of "Hello") {
176176
}
177177
```
178178

179-
## Strings are immutable
179+
## String bersifat tidak dapat dirubah
180180

181-
Strings can't be changed in JavaScript. It is impossible to change a character.
181+
Nilai dari string tidak dapat dirubah di Javascript. Tidak dimungkinkan untuk mengubah sebuah karakter.
182182

183-
Let's try it to show that it doesn't work:
183+
Mari kita coba untuk membuktikannya:
184184

185185
```js run
186186
let str = 'Hi';
@@ -189,9 +189,9 @@ str[0] = 'h'; // error
189189
alert( str[0] ); // doesn't work
190190
```
191191

192-
The usual workaround is to create a whole new string and assign it to `str` instead of the old one.
192+
Salah satu cara untuk mengatasi hal tersebut adalah untuk membuat string baru lalu memasukkan nilainya ke `str`.
193193

194-
For instance:
194+
Sebagai contoh:
195195

196196
```js run
197197
let str = 'Hi';
@@ -201,34 +201,34 @@ str = 'h' + str[1]; // replace the string
201201
alert( str ); // hi
202202
```
203203

204-
In the following sections we'll see more examples of this.
204+
Di bab ini kita akan melihat contoh yang lebih banyak dari ini.
205205

206-
## Changing the case
206+
## Mengganti case dari string
207207

208-
Methods [toLowerCase()](mdn:js/String/toLowerCase) and [toUpperCase()](mdn:js/String/toUpperCase) change the case:
208+
Method [toLowerCase()](mdn:js/String/toLowerCase) dan [toUpperCase()](mdn:js/String/toUpperCase) mengganti case dari string:
209209

210210
```js run
211211
alert( 'Interface'.toUpperCase() ); // INTERFACE
212212
alert( 'Interface'.toLowerCase() ); // interface
213213
```
214214

215-
Or, if we want a single character lowercased:
215+
Atau, apabila kita hanya ingin sebuah karakter yang diubah menjadi huruf kecil:
216216

217217
```js
218218
alert( 'Interface'[0].toLowerCase() ); // 'i'
219219
```
220220

221-
## Searching for a substring
221+
## Mencari sebuah substring
222222

223-
There are multiple ways to look for a substring within a string.
223+
Ada banyak cara untuk mencari sebuah substring di dalam sebuah string.
224224

225225
### str.indexOf
226226

227-
The first method is [str.indexOf(substr, pos)](mdn:js/String/indexOf).
227+
Cara yang pertama yaitu [str.indexOf(substr, pos)](mdn:js/String/indexOf).
228228

229-
It looks for the `substr` in `str`, starting from the given position `pos`, and returns the position where the match was found or `-1` if nothing can be found.
229+
Method ini mencari `substr` di dalam `str`, mulai dari posisi `pos` yang diberikan, dan mengembalikan posisi dimana substring ditemukan atau `-1` jika tidak ditemukan.
230230

231-
For instance:
231+
Sebagai contoh:
232232

233233
```js run
234234
let str = 'Widget with id';
@@ -239,17 +239,17 @@ alert( str.indexOf('widget') ); // -1, not found, the search is case-sensitive
239239
alert( str.indexOf("id") ); // 1, "id" is found at the position 1 (..idget with id)
240240
```
241241

242-
The optional second parameter allows us to search starting from the given position.
242+
Parameter kedua yang opsional memperbolehkan kita untuk mencari dari posisi yang ditentukan.
243243

244-
For instance, the first occurrence of `"id"` is at position `1`. To look for the next occurrence, let's start the search from position `2`:
244+
Sebagai contoh, `"id"` muncul pertama pada posisi `1`. Untuk mencari dimana yang selanjutnya terletak, mari kita mulai mencari dari posisi `2`:
245245

246246
```js run
247247
let str = 'Widget with id';
248248

249249
alert( str.indexOf('id', 2) ) // 12
250250
```
251251

252-
If we're interested in all occurrences, we can run `indexOf` in a loop. Every new call is made with the position after the previous match:
252+
Jika kita tertarik dengan semua kemunculan, kita dapat menjalankan `indexOf` di dalam sebuah perulangan. Setiap panggilan dibuat dengan posisi dari kemunculan sebelumnya:
253253

254254
```js run
255255
let str = 'As sly as a fox, as strong as an ox';
@@ -266,7 +266,7 @@ while (true) {
266266
}
267267
```
268268

269-
The same algorithm can be layed out shorter:
269+
Algoritma yang sama dapat ditulis lebih singkat:
270270

271271
```js run
272272
let str = "As sly as a fox, as strong as an ox";
@@ -281,12 +281,12 @@ while ((pos = str.indexOf(target, pos + 1)) != -1) {
281281
```
282282

283283
```smart header="`str.lastIndexOf(substr, position)`"
284-
There is also a similar method [str.lastIndexOf(substr, position)](mdn:js/String/lastIndexOf) that searches from the end of a string to its beginning.
284+
Ada juga method yang hampir sama [str.lastIndexOf(substr, position)](mdn:js/String/lastIndexOf) yang mencari dari akhir sebuah string sampai ke awalnya.
285285

286-
It would list the occurrences in the reverse order.
286+
Cara tersebut akan menemukan kemunculan dalam urutan yang terbalik.
287287
```
288288
289-
There is a slight inconvenience with `indexOf` in the `if` test. We can't put it in the `if` like this:
289+
Ada sedikit kerepotan dalam menggunakan `indexOf` di dalam `if`. Kita tidak dapat menggunakannya seperti ini:
290290
291291
```js run
292292
let str = "Widget with id";
@@ -296,9 +296,9 @@ if (str.indexOf("Widget")) {
296296
}
297297
```
298298

299-
The `alert` in the example above doesn't show because `str.indexOf("Widget")` returns `0` (meaning that it found the match at the starting position). Right, but `if` considers `0` to be `false`.
299+
Contoh di atas tidak bekerja karena `str.indexOf("Widget")` mengembalikan `0` (artinya kemunculan ditemukan di awal string). `if` menganggap `0` sebagai `false`.
300300

301-
So, we should actually check for `-1`, like this:
301+
Jadi, kita harus mengecek dengan nilai `-1`, seperti ini:
302302

303303
```js run
304304
let str = "Widget with id";

0 commit comments

Comments
 (0)