المسارات / JavaScript / المرجع / String.startsWith

مرجع · String

String.startsWith

String.startsWith بترجّع true لو النص بيبدأ بالنص اللي تديه، وبتقبل تحدد من أي index يبدأ الفحص.

What does String.startsWith() do in JavaScript?

js
str.startsWith(search, position?)

الـposition الاختياري بيحدد من أنهي index تبدأ المقارنة. زي includes: حساسة للحالة وبترفض regex.

البرهان

شُغّل على Node v26.14.0، والناتج منسوخ من التشغيل نفسه.

js
const url = 'https://example.com';
console.log(url.startsWith('https://'));
console.log(url.startsWith('HTTPS'));
console.log(url.startsWith('example', 8));
console.log(url.startsWith(''));
النتيجة
true
false
true
true

الدروس اللي بتشرحها

الصفحة دي على MDN ↗

ابعت الصفحة لحد
واتسابتليجرامX
برهان

الدروس

اتحلّ 0 من 174 تمرين