String methods in JavaScript.! part(1).
Published: 2024-06-25 12:31:55

**String methods in javascript**

JavaScript String malumot turida quyidagi string metodlari mavjud, va ularni birma-bir  ko'ribchiqamiz.!

`String length
String charAt()
String charCodeAt()
String at()
String [ ]
String slice()
String substring()
String substr()
String toUpperCase()
String toLowerCase()
String concat()
String trim()
String trimStart()
String trimEnd()
String padStart()
String padEnd()
String repeat()
String replace()
String replaceAll()
String split()`

1. <u>**`length`**</u> 

**string**-metodi stringda nechta belgi qatnashganini "uzunligini" aniqlaydi va natijani qaytaradi, qoldiribketilgan bitta  bo'sh joyham bitta belgi o'rnida o'tadi.!
```
let myEmail = 'samandarhodiev04@gmail.com';
console.log(myEmail);
//natija - samandarhodiev04@gmail.com

let length_ = myEmail.length;
console.log(length_);
//natija - 26 
```

string elementlarini chiqarishning quyidagi 4 ta usuli mavjud.!
`String charAt()
String charCodeAt()
String at()
String [ ]`

2.<u>**`charAt()`**</u> 
string charAt metodi charAt() qavslari ichida yoilgan raqamga mos indeksdagi string elementini qaytaradi.!
```
let myEmail = 'samandarhodiev04@gmail.com';
console.log(myEmail);
//natija - samandarhodiev04@gmail.com

let charAt_ = myEmail.charAt(0);
console.log(charAt_);
//natija - s
```


3.<u>**`charCodeAt()`**</u>
string charCodeAt() metodi charCodeAt() qavslari ichida yoilgan raqamga mos indeksdagi string elementning belgi kodini qaytaradi.!

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

let charCodeAt_ = myEmail.charCodeAt(0);
console.log(charCodeAt_);
//natija - 115
```


4.<u>**`At()`**</u>
string At() metodi At() qavslari ichida yoilgan raqamga mos indeksdagi string elementini qaytaradi, ushbu metod ES 2022 da taqdim etilgan va 2022-yil mart oyidan boshlab barcha brauzerlarda qo'llab-quvatlana boshlagan. At()- metodi manfiy indekslardan foydalanish imkoniniham beradi.!
```
let myEmail = 'samandarhodiev04@gmail.com';
console.log(myEmail);
//natija - samandarhodiev04@gmail.com

let at_1 = myEmail.at(22);
console.log(at_1);
//natija - .

let at_2 = myEmail.at(-22);
console.log(at_2);
//natija - n
```


5.**`[ ]`**
```
let myEmail = 'samandarhodiev04@gmail.com';
console.log(myEmail);
//natija - samandarhodiev04@gmail.com

console.log(myEmail[1]);
//natija - a

console.log(myEmail[-1]);
//natija - undefined

console.log(myEmail[12]);
//natija - e
```


**String elementining bir qismni chiqaribolish.!**
string elementining bir qismni chiqaribolishning 3 ta usuli mavjud ular quyidagilar.!
`String slice()
String substring()
String substr()`

<u>sintaksis:</u>
`slice(start, end)
substring(start, end)
substr(start, length)`



6.<u>**`slice()`**</u>
ushbu metod string elementidan malum qismni chiqaribolish uchun ishlatiladi, <u>sintaksis: slice(start, end);</u> start-chiqarib olinishi kerak bo'lgan element qayrdan boshlanishi kerakligini belgilaydi end-qayrda tugashini belgilaydi, agar qayerda tugashi kerakligini belgilamasak belgilangan qismdan boshlab oxrigacha chiqariboladi. slice() metodi asl stringga ta'sir qilmaydi.!

 
`0s1a2m3a4n5d6a7r8h9o10d11i12e13v14015416@17g18m19a20i21l22.23c24o25m26`

`(-25)s(-24)a(-23)m(-22)a(-21)n(-20)d(-19)a(-18)r(-17)h(-16)o(-15)d(-14)i(-13)e(-12)v(-11)0(-10)4(-9)@(-8)g(-7)m(-6)a()i(-5)l(-4).(-3)c(-2)o(-1)m(0)`
USHBU RAAQAMLASH STRING ELEMENTINI BIR QISMINI CHIQARIB OLISH METODLARI QANDAY ISHLAYOTGANINI YANADA USHUNARLIQILADI.



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

let slice_1 = myEmail.slice(8,14);
console.log(slice_1);
//natija - hodiev

let slice_2 = myEmail.slice(8);
console.log(slice_2);
//natija - hodiev04@gmail.com

let slice_3 = myEmail.slice(-18,-12);
console.log(slice_3);
//natija - hodiev

console.log(myEmail);
//natija - samandarhodiev04@gmail.com

```


7.<u>**`substring()`**</u>
ushbu metod string elementidan malum qismni chiqaribolish uchun ishlatiladi, <u>sintaksis: substring(start, end);</u> start-chiqarib olinishi kerak bo'lgan element qayrdan boshlanishi kerakligini belgilaydi end-qayrda tugashini belgilaydi, agar qayerda tugashi kerakligini belgilamasak belgilangan qismdan boshlab oxrigacha chiqariboladi.!

substring() slice() bilan birxil ishlashiga qaramasdan ular orasida bir farq bor: substring()  manfiy boshlang'ich va tugash qiymatni nol deb qabul qiladi.!

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

let substring_1 = myEmail.substring(17,26);
console.log(substring_1);
//natija - gmail.com

let substring_2 = myEmail.substring(8);
console.log(substring_2);
//natija - hodiev04@gmail.com

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


8.<u>**`substr()`**</u>

<u>sintaksis: substr(item,length)</u>
ushbu metod slice() ga o'xhsaydi farqi shuki item-qayerdan boshlab chiqarilishi kerakligini belgilasa length-chiqishi kerak bo'lgan elementning uzunligini belgilaydi, agar birinchi pozitsiya manfiy bo'lsa chiqarib olinishi kerak bo'lgan qismni text oxiridan boshlab xisoblaydi.!

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

let substr_1 = myEmail.substr(12,6);
console.log(substr_1);
//natija - ev04@g

let substr_2 = myEmail.substr(-9, 5);
console.log(substr_2);
//natija - gmail

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

 
9.<u>**`toUpperCase()`**</u>
Ushbu metod string elementini katta xarfli tekstga o'giribberadi.!

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

let toUpp_ = myEmail.toUpperCase();
console.log(toUpp_);
//natija - SAMANDARHODIEV04@GMAIL.COM
```


10.<u>**`toLowerCase()`**</u>
Ushbu metod string elementini kchik xarfli tekstga o'giribberadi.!
```
let myEmail = 'SAMANDARHODIEV04@GMAIL.COM';
console.log(myEmail);
//natija - SAMANDARHODIEV04@GMAIL.COM

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