Java Script uchun qo’llanma Samarqand Davlat universiteti talabasi Ibrohimov Ismoiljon tomonidan tayyorlandi. Kamchiliklar uchun uzr…!


Download 227.69 Kb.
bet8/22
Sana04.04.2023
Hajmi227.69 Kb.
#1325028
1   ...   4   5   6   7   8   9   10   11   ...   22
Bog'liq
JS ( Ibrohimov )

Eslatma


Usul replace()chaqirilgan satrni o'zgartirmaydi.
Usul replace()yangi qatorni qaytaradi.
Usul faqat birinchi moslikni replace()almashtiradi
let text = "Please visit Microsoft and Microsoft!";
let newText = text.replace("Microsoft", "W3Schools");
// Please visit Microsoft and Microsoft!

2021 yilda JavaScript string usulini taqdim etdi replaceAll():


Misol


let text = "I love cats. Cats are very easy to love. Cats are very popular."
text = text.replaceAll("Cats","Dogs");
text = text.replaceAll("cats","dogs");
// I love dogs. Dogs are very easy to love. Dogs are very popular.

Satr quyidagi bilan katta harfga aylantiriladi toUpperCase():


Satr quyidagi bilan kichik harfga aylantiriladi toLowerCase():
concat() ikki yoki undan ortiq qatorlarni birlashtiradi:

text = "Hello" + " " + "World!";


text = "Hello".concat(" ", "World!");


ECMAScript 2019 JavaScript-ga String trimStart() usulini qo'shdi .


Usul trimStart() trim() kabi ishlaydi , lekin bo'shliqni faqat satr boshidan olib tashlaydi.
Usul trimEnd() trim() kabi ishlaydi , lekin bo'shliqni faqat satr oxiridan olib tashlaydi.

ECMAScript 2017 ikkita String usulini qo'shdi: padStart() va padEnd()satr boshida va oxirida to'ldirishni qo'llab-quvvatlash uchun.


Usul padStart()satrni boshqa satr bilan to'ldiradi:

Misol


let text = "5";
let padded = text.padStart(4,"x"); // xxx5

Misol
let text = "5";


let padded = text.padStart(4,"0"); // 0005


let numb = 5;


let text = numb.toString();
let padded = text.padStart(4,"0"); // 0005

Usul padEnd()satrni boshqa satr bilan to'ldiradi:


Misol


let text = "5";
let padded = text.padEnd(4,"x"); // 5xxx


Satr belgilarini ajratib olishning 3 ta usuli mavjud:



  • charAt(position)

  • charCodeAt(position)

  • Mulkga kirish [ ]

Usul charAt()satrdagi belgilangan indeks (pozitsiya)dagi belgini qaytaradi:

Misol


let text = "HELLO WORLD";
let char = text.charAt(0); // H
Usul charCodeAt()satrda belgilangan indeksdagi belgining unikodini qaytaradi:
Usul UTF-16 kodini qaytaradi (0 dan 65535 gacha bo'lgan butun son).
Misol
let text = "HELLO WORLD";
let char = text.charCodeAt(0); // 72

ECMAScript 5 (2009) satrlarda [ ] mulkiga kirish imkonini beradi:


Misol


let text = "HELLO WORLD";
let char = text[0]; // H


Agar siz satr bilan massiv sifatida ishlamoqchi bo'lsangiz, uni massivga aylantirishingiz mumkin.


Satrni quyidagi usul bilan massivga aylantirish mumkin split():

Misol



Download 227.69 Kb.

Do'stlaringiz bilan baham:
1   ...   4   5   6   7   8   9   10   11   ...   22




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling