aboutsummaryrefslogtreecommitdiff
path: root/files/ar/web/javascript/reference/global_objects/string/startswith/index.html
blob: 94b059d593fa67676d6a5387b67fc8b745c958a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
---
title: String.prototype.startsWith()
slug: Web/JavaScript/Reference/Global_Objects/String/startsWith
translation_of: Web/JavaScript/Reference/Global_Objects/String/startsWith
---
<div>{{JSRef}}</div>

<p dir="rtl"><span class="seoSummary"><strong><code>startsWith()</code></strong></span><br>
 <span class="seoSummary">.طريقة يمكنك<strong> تحقق</strong> بها<strong> إن كان </strong><code>نص</code> <strong>يبدء بالعبارة ما</strong> و تعيد لك<code> صحيح </code>أو <code>خطأ</code> </span></p>

<div>{{EmbedInteractiveExample("pages/js/string-startswith.html")}}</div>



<h2 dir="rtl" id="تركيب_الجملة_Syntax">تركيب الجملة | Syntax</h2>

<pre class="syntaxbox"><var>str</var>.startsWith(<var>searchString</var>[, <var>position</var>])</pre>

<h3 dir="rtl" id="المعاملات_Parameters">المعاملات | Parameters</h3>

<dl>
 <dt><code>searchString</code></dt>
 <dd dir="rtl">العبارة<strong> المبحوث عنها</strong> في<strong><code>النص.</code></strong></dd>
 <dt><code>position </code>{{optional_inline}}</dt>
 <dd dir="rtl">مكان الذي<strong> يبدأ البحث منه </strong>في<code><strong>النص </strong></code>  <strong>الإفتراضي 0</strong></dd>
</dl>

<h3 dir="rtl" id="القيمة_العائدة_Return_value">القيمة العائدة | Return value</h3>

<p dir="rtl"><strong>العائد</strong> يكون<strong> صحيح</strong> إذا وجد <strong>تطابق</strong><br>
 و إن <strong>لم يجيد تطابق</strong> يعيد لك <strong>خطأ</strong></p>

<h2 dir="rtl" id="الوصف_Description">الوصف | Description</h2>

<p dir="rtl"><strong><code>هذه الطريقة حساسة إتجاه الحروف<br>
 case-sensitive</code></strong></p>

<h2 dir="rtl" id="أمثلة_Examples">أمثلة | Examples</h2>

<h3 id="Using_startsWith()">Using <code>startsWith()</code></h3>

<pre class="brush: js">//startswith
var str = 'To be, or not to be, that is the question.';

console.log(str.startsWith('To be'));         // true
console.log(str.startsWith('not to be'));     // false
console.log(str.startsWith('not to be', 10)); // true
</pre>

<h2 id="Polyfill">Polyfill</h2>

<p>This method has been added to the ECMAScript 2015 specification and may not be available in all JavaScript implementations yet. However, you can polyfill <code>String.prototype.startsWith()</code> with the following snippet:</p>

<pre class="brush: js">if (!String.prototype.startsWith) {
    Object.defineProperty(String.prototype, 'startsWith', {
        value: function(search, pos) {
            pos = !pos || pos &lt; 0 ? 0 : +pos;
            return this.substring(pos, pos + search.length) === search;
        }
    });
}
</pre>

<p>A more robust (fully ES2015 specification compliant), but less performant and compact, Polyfill is available <a href="https://github.com/mathiasbynens/String.prototype.startsWith">on GitHub by Mathias Bynens</a>.</p>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('ES2015', '#sec-string.prototype.startswith', 'String.prototype.startsWith')}}</td>
   <td>{{Spec2('ES2015')}}</td>
   <td>Initial definition.</td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-string.prototype.startswith', 'String.prototype.startsWith')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td></td>
  </tr>
 </tbody>
</table>

<h2 dir="rtl" id="توافق_مع_متصفحات">توافق مع متصفحات</h2>

<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>

<p>{{Compat("javascript.builtins.String.startsWith")}}</p>

<h2 dir="rtl" id="ذات_صلة">ذات صلة</h2>

<ul>
 <li>{{jsxref("String.prototype.endsWith()")}}</li>
 <li>{{jsxref("String.prototype.includes()")}}</li>
 <li>{{jsxref("String.prototype.indexOf()")}}</li>
 <li>{{jsxref("String.prototype.lastIndexOf()")}}</li>
</ul>