diff options
Diffstat (limited to 'files/ar/web/javascript/reference/global_objects/string/startswith/index.html')
| -rw-r--r-- | files/ar/web/javascript/reference/global_objects/string/startswith/index.html | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/files/ar/web/javascript/reference/global_objects/string/startswith/index.html b/files/ar/web/javascript/reference/global_objects/string/startswith/index.html new file mode 100644 index 0000000000..94b059d593 --- /dev/null +++ b/files/ar/web/javascript/reference/global_objects/string/startswith/index.html @@ -0,0 +1,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 < 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> |
