String methods in JavaScript.! part(2)
Published: 2024-06-25 13:59:24


11.<u>**`concat()`**</u>
Ikta yoki birnechta qatorlarni birlashtirish uchun ishlatiladi.!

```
let fName_ = 'samandar';
let lName_ = 'hodiev';

let l_f_Name_ = fName_.concat( lName_);
console.log(l_f_Name_);
//natija - samandarhodiev
```


12.<u>**`trim()`**</u>

Ushbu metod string elementining boshlanish va tugash qismida qolgan bo'sh joyni olibtashlaydi.!

```
let myEmail = "  samandarhodiev04@gmail.com     ";
console.log(myEmail);
//natija -  (start)  samandarhodiev04@gmail.com     (end)

let trim_ = myEmail.trim();
console.log(trim_);
//natija - (string start)samandarhodiev04@gmail.com(string end)
```


13.<u>**`trimStart()`**</u>
Ushbu metod string elementining boshlanish  qismida qolgan bo'sh joyni olibtashlaydi va asl string elementiga ta'sir qilmaydi, trimStart() ECMAScript 2019 JavaScript-ga qo'shilgan.!

```
let myEmail = "  samandarhodiev04@gmail.com     ";
console.log(myEmail);
//natija -  (string start)  samandarhodiev04@gmail.com     (string end)

let trim_ = myEmail.trimStart();
console.log(trim_);
//natija - (string start)samandarhodiev04@gmail.com    (string end)
```


14.<u>**`trimEnd()`**</u>
Ushbu metod string elementining tugash qismida qolgan bo'sh joyni olibtashlaydi va asl string elementiga ta'sir qilmaydi, trimEnd() ECMAScript 2019 JavaScript-ga qo'shilgan.!


```
let myEmail = "  samandarhodiev04@gmail.com     ";
console.log(myEmail);
//natija -  (string start)  samandarhodiev04@gmail.com     (string end)

let trim_ = myEmail.trimEnd();
console.log(trim_);
//natija - (string start)   samandarhodiev04@gmail.com(string end)
```


15.<u>**`padStart()`**</u>
String satrini boshidan to'ldirish uchun ishlatiladi, ushbu metod ECMAScript 2017 da  qo'shilgan.!
<u>sintaksis:</u> `padStart(rooms, sign) ` Bu yerda **rooms** - string satirimiz nechta xonadan tashkil topishini belgilaydi, **sign** - esa  belgilangan xonaga yetgungacha qanday belgi bilan to'lishi kerak ekanligini belgilaydi.!


```
let myEmail = "samandarhodiev04@gmail.com";
console.log(myEmail);
//natija - samandarhodiev04@gmail.com

let padStart_1 = myEmail.padStart(32, 'o')
console.log(padStart_1);
//natija - oooooosamandarhodiev04@gmail.com

let padStart_2 = myEmail.padStart(35, 24)
console.log(padStart_2);
//natija - 242424242samandarhodiev04@gmail.com
```



16.<u>**`padEnd`**</u>
String satrini oxiridan to'ldirish uchun ishlatiladi, ushbu metod ECMAScript 2017 da  qo'shilgan.!
<u>sintaksis:</u> `padEnd(rooms, sign) ` Bu yerda **rooms** - string satirimiz nechta xonadan tashkil topishini belgilaydi, **sign** - esa  belgilangan xonaga yetgungacha qanday belgi bilan to'lishi kerak ekanligini belgilaydi.!

```
let myEmail = "samandarhodiev04@gmail.com";
console.log(myEmail);
//natija - samandarhodiev04@gmail.com 

let padEnd_1 = myEmail.padEnd(32,'A');
console.log(padEnd_1);
//natija - samandarhodiev04@gmail.comAAAAAA

let padEnd_2 = myEmail.padEnd(40,40);
console.log(padEnd_2);
//natija - samandarhodiev04@gmail.com40404040404040
```


17.<u>**`repeat()`**</u>
Ushbu metod string satrini necha marta takrorlanishini belgilaydi, asl stringga ta'sir qilmaydi.!
<u>sintaksis:</u> `.repeat(count)`

```
let myEmail = "samandarhodiev04@gmail.com";
console.log(myEmail);
//natija - samandarhodiev04@gmail.com 

let repeat_ = myEmail.repeat(4);
console.log(repeat_);
//natija - samandarhodiev04@gmail.comsamandarhodiev04@gmail.comsamandarhodiev04@gmail.comsamandarhodiev04@gmail.com
```


18.<u>**`replace()`**</u>
Ushbu metod string satr elementini almashtirish uchun ishlatiladi, ag global almash uchun /g ishlatiladi.!


```
let myEmail = "samandarhodiev04@gmail.com";
console.log(myEmail);
//natija - samandarhodiev04@gmail.com 

let replace_ = myEmail.replace('.com', '.me');
console.log(replace_);
//natija - samandarhodiev04@gmail.me


let fruits_ = 'apple, banana, lemon, apple, mango, apple';
console.log(fruits_);
//natija - apple, banana, lemon, apple, mango, apple

let replace_1 = fruits_.replace('apple','pomegranate');
console.log(replace_1);
//natija - pomegranate, banana, lemon, apple, mango, apple

let replace_2 = fruits_.replace(/apple/g,'pomegranate');
console.log(replace_2);
//natija - pomegranate, banana, lemon, pomegranate, mango, pomegranate
```


19.<u>**`replaceAll()`**</u>
ES2021

```
let fruits_ = 'apple, banana, lemon, apple, mango, apple';
console.log(fruits_);
//natija - apple, banana, lemon, apple, mango, apple

let replaceAll_ = fruits_.replaceAll('apple', 'lemon');
console.log(replaceAll_);
//natija - lemon, banana, lemon, lemon, mango, lemon
```



20.<u>**`split()`**</u>
Ushbu metod string elementini massivga o'zgartiribberadi.!

```
let myEmail = "samandarhodiev04@gmail.com";
console.log(myEmail);
//natija - samandarhodiev04@gmail.com 


let split_1 = myEmail.split();
console.log(split_1);
//natija - ['samandarhodiev04@gmail.com']

let split_2 = myEmail.split('');
console.log(split_2);
//natija - ['s', 'a', 'm', 'a', 'n', 'd', 'a', 'r', 'h', 'o', 'd', 'i', 'e', 'v', '0', '4', '@', 'g', 'm', 'a', 'i', 'l', '.', 'c', 'o', 'm']

let split_3 = myEmail.split('a');
console.log(split_3);
//natija - ['s', 'm', 'nd', 'rhodiev04@gm', 'il.com']
```