DEV Community

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

Posted on • Edited on

String methods in JavaScript.! part(2)

11.concat()
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
Enter fullscreen mode Exit fullscreen mode

12.trim()

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

13.trimStart()
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)
Enter fullscreen mode Exit fullscreen mode

14.trimEnd()
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)
Enter fullscreen mode Exit fullscreen mode

15.padStart()
String satrini boshidan to'ldirish uchun ishlatiladi, ushbu metod ECMAScript 2017 da qo'shilgan.!
sintaksis: 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
Enter fullscreen mode Exit fullscreen mode

16.padEnd
String satrini oxiridan to'ldirish uchun ishlatiladi, ushbu metod ECMAScript 2017 da qo'shilgan.!
sintaksis: 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
Enter fullscreen mode Exit fullscreen mode

17.repeat()
Ushbu metod string satrini necha marta takrorlanishini belgilaydi, asl stringga ta'sir qilmaydi.!
sintaksis: .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
Enter fullscreen mode Exit fullscreen mode

18.replace()
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
Enter fullscreen mode Exit fullscreen mode

19.replaceAll()
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
Enter fullscreen mode Exit fullscreen mode

20.split()
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']
Enter fullscreen mode Exit fullscreen mode

Top comments (0)