diff options
Diffstat (limited to 'files/nl/web/javascript/reference/global_objects/string/startswith/index.html')
| -rw-r--r-- | files/nl/web/javascript/reference/global_objects/string/startswith/index.html | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/files/nl/web/javascript/reference/global_objects/string/startswith/index.html b/files/nl/web/javascript/reference/global_objects/string/startswith/index.html new file mode 100644 index 0000000000..b183929746 --- /dev/null +++ b/files/nl/web/javascript/reference/global_objects/string/startswith/index.html @@ -0,0 +1,96 @@ +--- +title: String.prototype.startsWith() +slug: Web/JavaScript/Reference/Global_Objects/String/startsWith +tags: + - Begin + - JavaScript + - Méthode + - String +translation_of: Web/JavaScript/Reference/Global_Objects/String/startsWith +--- +<div>{{JSRef}}</div> + +<p><span class="seoSummary">De <strong><code>startsWith()</code></strong> methode bepaalt of een string begint met de karakters van een bepaalde string. Deze geeft <code>true</code> of <code>false</code> terug waar nodig.</span></p> + +<h2 id="Syntax">Syntax</h2> + +<pre class="syntaxbox"><var>str</var>.startsWith(<em>zoek</em><var>String</var>[, <var>positie</var>])</pre> + +<h3 id="Parameters">Parameters</h3> + +<dl> + <dt><code>zoekString</code></dt> + <dd>De karakters om te zoeken aan het begin van de string.</dd> + <dt><code>positie</code>{{optional_inline}}</dt> + <dd>De positie in de string waar je start met zoeken naar <code>zoekString</code>; start standaard op 0.</dd> +</dl> + +<h3 id="Resultaat">Resultaat</h3> + +<p><strong><code>true</code></strong> als de karakters teruggevonden worden aan het begin van de string, anders <strong><code>false</code></strong>.</p> + +<h2 id="Beschrijving">Beschrijving</h2> + +<p>Deze methde laat je nagaan of een string begint met een andere string. Dit is hoofdletter gevoelig</p> + +<h2 id="Voorbeelden">Voorbeelden</h2> + +<h3 id="Gebruik_startsWith()">Gebruik <code>startsWith()</code></h3> + +<pre class="brush: js">//startswith +var str = 'Te nemen of te laten.'; + +console.log(str.startsWith('Te nemen')); // true +console.log(str.startsWith('te laten')); // false +console.log(str.startsWith('te laten', 12)); // true +</pre> + +<h2 id="Polyfill">Polyfill</h2> + +<p>Deze methode is toegevoegd aan de ECMAScript 2015 specificaties en is misschien nog niet beschikbaar in alle JavaScript implementaties. Je kan wel Polyfill <code>String.prototype.startsWith()</code> alsvolgt gebruiken</p> + +<pre class="brush: js">if (!String.prototype.startsWith) { + String.prototype.startsWith = function(search, pos) { + return this.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search; + }; +} +</pre> + +<p>Een meer degelijke en geoptimaliseerde Polyfill is beschikbaar <a href="https://github.com/mathiasbynens/String.prototype.startsWith">op GitHub door Mathias Bynens</a>.</p> + +<h2 id="Specificaties">Specificaties</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specificatie</th> + <th scope="col">Status</th> + <th scope="col">Commentaar</th> + </tr> + <tr> + <td>{{SpecName('ES2015', '#sec-string.prototype.startswith', 'String.prototype.startsWith')}}</td> + <td>{{Spec2('ES2015')}}</td> + <td>Eerste definitie.</td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-string.prototype.startswith', 'String.prototype.startsWith')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibiliteit">Browser compatibiliteit</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 id="Meer_lezen">Meer lezen</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> |
