DEV Community

Cover image for String methods in JavaScript.! part(1).
Hodiev
Hodiev

Posted on • Edited on

String methods in JavaScript.! part(1).

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. length

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 
Enter fullscreen mode Exit fullscreen mode

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

2.charAt()
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
Enter fullscreen mode Exit fullscreen mode

3.charCodeAt()
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
Enter fullscreen mode Exit fullscreen mode

4.At()
string At() metodi At() qavslari ichida yozilgan 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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

sintaksis:
slice(start, end)
substring(start, end)
substr(start, length)

6.slice()
ushbu metod string elementidan malum qismni chiqaribolish uchun ishlatiladi, sintaksis: slice(start, end); 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 tUSHUNARLIQILADI.

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

Enter fullscreen mode Exit fullscreen mode

7.substring()
ushbu metod string elementidan malum qismni chiqaribolish uchun ishlatiladi, sintaksis: substring(start, end); 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
Enter fullscreen mode Exit fullscreen mode

8.substr()

sintaksis: substr(item,length)
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
Enter fullscreen mode Exit fullscreen mode

9.toUpperCase()
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
Enter fullscreen mode Exit fullscreen mode

10.toLowerCase()
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


Enter fullscreen mode Exit fullscreen mode

Top comments (0)