The matchAll() Method
ES2020 intoduced the string method matchAll().
Cats,Cats
includes () Agar satrda belgilangan qiymat bo'lsa, usul true ni qaytaradi .
Aks holda false qaytib keladi.
JavaScript Strings
The includes() Method
Check if a string includes "world":
NATIJA :: :
JavaScript Strings The includes() Method
Check if a string includes "world":
true
Satrda "world" mavjudligini tekshiring. 12-pozitsiyadan boshlang:
let text = "Hello world, welcome to the universe.";
text.includes("world", 12);
// false
Agar satr belgilangan qiymatdan boshlansa, usul startsWith() true qaytariladi . Aks holda false :
The startsWith() method is not supported in Internet Explorer.
NATIJA :: :
true
Bu yerda berilgan satr Hello so’zidan boshlangani uchun true qiymati qaytardi.
Agar text.startsWith(world) bo’lganda false qaytarar edi…
Qidiruv uchun boshlang'ich pozitsiyasi belgilanishi mumkin:
let text = "Hello world, welcome to the universe.";
text.startsWith("world", 6) ;
// true
world so’zi 6-indexdan boshlangani uchun true qiymat qaytariladi.
Agar satr belgilangan qiymat bilan tugasa, endsWith () true qaytariladi .
Aks holda u false :
let text = "John Doe";
text.endsWith("Doe"); // true
Satrning 11 ta birinchi belgisi "world" bilan tugashini tekshiring:
let text = "Hello world, welcome to the universe.";
text.endsWith("world", 11); // true
Bu yerda world so’zi 11-index bilan tugagani uchun true qiymat qaytaradi.
Do'stlaringiz bilan baham: |