diff options
Diffstat (limited to 'files/tr/web/javascript/reference/global_objects/array/includes/index.html')
-rw-r--r-- | files/tr/web/javascript/reference/global_objects/array/includes/index.html | 176 |
1 files changed, 0 insertions, 176 deletions
diff --git a/files/tr/web/javascript/reference/global_objects/array/includes/index.html b/files/tr/web/javascript/reference/global_objects/array/includes/index.html deleted file mode 100644 index 7ccb8cebc9..0000000000 --- a/files/tr/web/javascript/reference/global_objects/array/includes/index.html +++ /dev/null @@ -1,176 +0,0 @@ ---- -title: Array.prototype.includes() -slug: Web/JavaScript/Reference/Global_Objects/Array/includes -translation_of: Web/JavaScript/Reference/Global_Objects/Array/includes ---- -<div>{{JSRef}}</div> - -<p><code><strong>includes()</strong></code> metodu bir dizinin belirli bir elemanı içerip içermediğini belirler, içeriyorsa <code>true</code> içermiyorsa <code>false</code> değeri döndürür. Aranan öğenin bulunup bulunmadığını belirlemek için <code>sameValueZero</code> algoritmasını kullanır.</p> - -<pre class="brush: js">var a = [1, 2, 3]; -a.includes(2); // true -a.includes(4); // false -</pre> - -<p>{{EmbedInteractiveExample("pages/js/array-includes.html")}} </p> - -<div> -<div class="hidden">The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> and send us a pull request.</div> -</div> - -<h2 id="Söz_Dizimi">Söz Dizimi</h2> - -<pre class="syntaxbox"><var>arr</var>.includes(<var>searchElement</var>) -<var>arr</var>.includes(<var>searchElement</var>, <var>fromIndex</var>) -</pre> - -<h3 id="Parametreler">Parametreler</h3> - -<dl> - <dt><code>searchElement</code></dt> - <dd>Aranan eleman.</dd> - <dt><code>fromIndex</code> {{optional_inline}}</dt> - <dd>Dizide <code>searchElement</code> için aramanın başlatılacağı indis. Negatif bir değer, dizinin sonundan aramaya başlar. Varsayılan değer 0'dır.</dd> -</dl> - -<h3 id="Return_value">Return value</h3> - -<p>A {{jsxref("Boolean")}}.</p> - -<h2 id="Örnekler">Örnekler</h2> - -<pre class="brush: js">[1, 2, 3].includes(2); // true -[1, 2, 3].includes(4); // false -[1, 2, 3].includes(3, 3); // false -[1, 2, 3].includes(3, -1); // true -[1, 2, NaN].includes(NaN); // true -</pre> - -<h3 id="fromIndex_dizi_uzunluğundan_büyük_veya_eşitse"><code>fromIndex</code> dizi uzunluğundan büyük veya eşitse</h3> - -<p>Eğer <code>fromIndex</code> dizinin uzunluğundan büyük veya eşitse, false döndürülür. Dizi aranmaz.</p> - -<pre class="brush: js">var arr = ['a', 'b', 'c']; - -arr.includes('c', 3); //false -arr.includes('c', 100); // false</pre> - -<h3 id="Hesaplanan_indis_0'dan_küçükse">Hesaplanan indis 0'dan küçükse</h3> - -<p>Eğer <code>fromIndex</code> negatifse, hesaplanan indis, <code>searchElement</code> için aramaya başlanacak konum olarak belirlenir. Hesaplanmış indis 0'dan küçükse, dizinin tamamı aranır.</p> - -<pre class="brush: js">// array length is 3 -// fromIndex is -100 -// computed index is 3 + (-100) = -97 - -var arr = ['a', 'b', 'c']; - -arr.includes('a', -100); // true -arr.includes('b', -100); // true -arr.includes('c', -100); // true</pre> - -<h3 id="includes()_genel_bir_yöntem_olarak_kullanılması"><code>includes()</code> genel bir yöntem olarak kullanılması</h3> - -<p><code>includes()</code> yöntemi kasıtlı olarak geneldir. <code>this</code> değerinin bir Array nesnesi türünde olmasını gerektirmez, böylece diğer türlerdeki nesnelere (örn: dizi benzeri nesneler) uygulanabilir. Aşağıdaki örnek, fonksiyonun sahip olduğu <a href="/en-US/docs/Web/JavaScript/Reference/Functions/arguments">argümanlar</a> nesnesi için uygulanan <code>includes()</code> metodunu göstermektedir.</p> - -<pre class="brush: js">(function() { - console.log([].includes.call(arguments, 'a')); // true - console.log([].includes.call(arguments, 'd')); // false -})('a','b','c');</pre> - -<h2 id="Polyfill">Polyfill</h2> - -<pre class="brush: js">// https://tc39.github.io/ecma262/#sec-array.prototype.includes -if (!Array.prototype.includes) { - Object.defineProperty(Array.prototype, 'includes', { - value: function(searchElement, fromIndex) { - - if (this == null) { - throw new TypeError('"this" is null or not defined'); - } - - // 1. Let O be ? ToObject(this value). - var o = Object(this); - - // 2. Let len be ? ToLength(? Get(O, "length")). - var len = o.length >>> 0; - - // 3. If len is 0, return false. - if (len === 0) { - return false; - } - - // 4. Let n be ? ToInteger(fromIndex). - // (If fromIndex is undefined, this step produces the value 0.) - var n = fromIndex | 0; - - // 5. If n ≥ 0, then - // a. Let k be n. - // 6. Else n < 0, - // a. Let k be len + n. - // b. If k < 0, let k be 0. - var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0); - - function sameValueZero(x, y) { - return x === y || (typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y)); - } - - // 7. Repeat, while k < len - while (k < len) { - // a. Let elementK be the result of ? Get(O, ! ToString(k)). - // b. If SameValueZero(searchElement, elementK) is true, return true. - if (sameValueZero(o[k], searchElement)) { - return true; - } - // c. Increase k by 1. - k++; - } - - // 8. Return false - return false; - } - }); -} -</pre> - -<p><code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty">Object.defineProperty</a></code> desteklemeyen eski JavaScript motorlarını desteklemeniz gerekiyorsa, <code>Array.prototype</code> metodlarını non-enumerable yapamadığımız için polyfill uygulamamak daha iyidir.</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('ES7', '#sec-array.prototype.includes', 'Array.prototype.includes')}}</td> - <td>{{Spec2('ES7')}}</td> - <td>Initial definition.</td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-array.prototype.includes', 'Array.prototype.includes')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibility">Browser compatibility</h2> - -<div> - - -<p>{{Compat("javascript.builtins.Array.includes")}}</p> -</div> - -<h2 id="See_also">See also</h2> - -<ul> - <li>{{jsxref("TypedArray.prototype.includes()")}}</li> - <li>{{jsxref("String.prototype.includes()")}}</li> - <li>{{jsxref("Array.prototype.indexOf()")}}</li> - <li>{{jsxref("Array.prototype.find()")}}</li> - <li>{{jsxref("Array.prototype.findIndex()")}}</li> -</ul> |