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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
---
title: Array.prototype.every()
slug: Web/JavaScript/Reference/Global_Objects/Array/every
translation_of: Web/JavaScript/Reference/Global_Objects/Array/every
---
<div>{{JSRef}}</div>
<div><code><strong>every()</strong></code> metodu bir dizideki tüm elemanların verilen fonksiyonun testini geçip geçmediği kontrol eder. Bu metot true (doğru) yada false (yanlış) olarak ikilik değer döndürür. </div>
<div class="note">
<p><strong>Note</strong>: Test edilen array boş ise bu metot true deger döndürür.</p>
</div>
<div>{{EmbedInteractiveExample("pages/js/array-every.html")}}</div>
<h2 id="Söz_dizimi">Söz dizimi</h2>
<pre class="syntaxbox">arr.every(callback(element[, index[, array]])[, thisArg])</pre>
<h3 id="Parametreler">Parametreler</h3>
<dl>
<dt><code>callback</code></dt>
<dd>Her elemanı test eden üç değişken alan bir fonksiyon:
<dl>
<dt><code>element</code></dt>
<dd>İşlemde olan geçerli dizi elemanı.</dd>
<dt><code>index</code>{{Optional_inline}}</dt>
<dd>İşlemde olan geçerli dizi elemanın indeksi .</dd>
<dt><code>array</code>{{Optional_inline}}</dt>
<dd><code>every</code> tarafından çağrılan dizi.</dd>
</dl>
</dd>
<dt><code>thisArg</code>{{Optional_inline}}</dt>
<dd>Geri dönüş yapıldığında <code>this</code> olarak kullanıcak bir değer.</dd>
</dl>
<h3 id="Dönüş_değeri">Dönüş değeri</h3>
<p>Geri dönüş fonksiyonu her bir dizi elemanı için bir {{Glossary("truthy")}} deger dondürse <code><strong>true</strong></code>. Aksi takdirde, <code><strong>false</strong></code>.</p>
<h2 id="Description">Description</h2>
<p>The <code>every</code> method executes the provided <code>callback</code> function once for each element present in the array until it finds the one where <code>callback</code> returns a {{Glossary("falsy")}} value. If such an element is found, the <code>every</code> method immediately returns <code>false</code>. Otherwise, if <code>callback</code> returns a {{Glossary("truthy")}} value for all elements, <code>every</code> returns <code>true</code>. <code>callback</code> is invoked only for indexes of the array which have assigned values; it is not invoked for indexes which have been deleted or which have never been assigned values.</p>
<p><code>callback</code> is invoked with three arguments: the value of the element, the index of the element, and the Array object being traversed.</p>
<p>If a <code>thisArg</code> parameter is provided to <code>every</code>, it will be used as callback's <code>this</code> value. Otherwise, the value <code>undefined</code> will be used as its <code>this</code> value. The <code>this</code> value ultimately observable by <code>callback</code> is determined according to <a href="/en-US/docs/Web/JavaScript/Reference/Operators/this">the usual rules for determining the <code>this</code> seen by a function</a>.</p>
<p><code>every</code> does not mutate the array on which it is called.</p>
<p>The range of elements processed by <code>every</code> is set before the first invocation of <code>callback</code>. Therefore, <code>callback</code> will not run on elements that are appended to the array after the call to <code>every</code> begins. If existing elements of the array are changed, their value as passed to <code>callback</code> will be the value at the time <code>every</code> visits them. Elements that are deleted are not visited.</p>
<p><code>every</code> acts like the "for all" quantifier in mathematics. In particular, for an empty array, it returns true. (It is <a href="http://en.wikipedia.org/wiki/Vacuous_truth">vacuously true</a> that all elements of the <a href="https://en.wikipedia.org/wiki/Empty_set#Properties">empty set</a> satisfy any given condition.)</p>
<h2 id="Örnekler">Örnekler</h2>
<h3 id="Tüm_dizi_elemanlarının_büyüklüğünün_test_edilmesi">Tüm dizi elemanlarının büyüklüğünün test edilmesi</h3>
<p>Aşağıdaki örnekte tüm dizi elemanlarının 10'dan büyük yada eşit olma durumu test edilir.</p>
<pre class="brush: js">function isBigEnough(element, index, array) {
return element >= 10;
}
[12, 5, 8, 130, 44].every(isBigEnough); // false
[12, 54, 18, 130, 44].every(isBigEnough); // true
</pre>
<h3 id="Ok_fonksiyonlarını_kullanma">Ok fonksiyonlarını kullanma</h3>
<p><a href="/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions">Ok fonksiyonları</a> aynı testin daha kısa söz dizimi ile yapılmasını sağlar.</p>
<pre class="brush: js">[12, 5, 8, 130, 44].every(x => x >= 10); // false
[12, 54, 18, 130, 44].every(x => x >= 10); // true</pre>
<h2 id="Polyfill">Polyfill</h2>
<p><code>every</code> was added to the ECMA-262 standard in the 5th edition, and it may not be present in other implementations of the standard. You can work around this by inserting the following code at the beginning of your scripts, allowing use of <code>every</code> in implementations which do not natively support it. This algorithm is exactly the one specified in ECMA-262, 5th edition, assuming <code>Object</code> and <code>TypeError</code> have their original values and that <code>callbackfn.call</code> evaluates to the original value of {{jsxref("Function.prototype.call")}}</p>
<pre class="brush: js">if (!Array.prototype.every) {
Array.prototype.every = function(callbackfn, thisArg) {
'use strict';
var T, k;
if (this == null) {
throw new TypeError('this is null or not defined');
}
// 1. Let O be the result of calling ToObject passing the this
// value as the argument.
var O = Object(this);
// 2. Let lenValue be the result of calling the Get internal method
// of O with the argument "length".
// 3. Let len be ToUint32(lenValue).
var len = O.length >>> 0;
// 4. If IsCallable(callbackfn) is false, throw a TypeError exception.
if (typeof callbackfn !== 'function') {
throw new TypeError();
}
// 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
if (arguments.length > 1) {
T = thisArg;
}
// 6. Let k be 0.
k = 0;
// 7. Repeat, while k < len
while (k < len) {
var kValue;
// a. Let Pk be ToString(k).
// This is implicit for LHS operands of the in operator
// b. Let kPresent be the result of calling the HasProperty internal
// method of O with argument Pk.
// This step can be combined with c
// c. If kPresent is true, then
if (k in O) {
// i. Let kValue be the result of calling the Get internal method
// of O with argument Pk.
kValue = O[k];
// ii. Let testResult be the result of calling the Call internal method
// of callbackfn with T as the this value and argument list
// containing kValue, k, and O.
var testResult = callbackfn.call(T, kValue, k, O);
// iii. If ToBoolean(testResult) is false, return false.
if (!testResult) {
return false;
}
}
k++;
}
return true;
};
}
</pre>
<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('ES5.1', '#sec-15.4.4.16', 'Array.prototype.every')}}</td>
<td>{{Spec2('ES5.1')}}</td>
<td>Initial definition. Implemented in JavaScript 1.6.</td>
</tr>
<tr>
<td>{{SpecName('ES6', '#sec-array.prototype.every', 'Array.prototype.every')}}</td>
<td>{{Spec2('ES6')}}</td>
<td></td>
</tr>
<tr>
<td>{{SpecName('ESDraft', '#sec-array.prototype.every', 'Array.prototype.every')}}</td>
<td>{{Spec2('ESDraft')}}</td>
<td></td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<div>
<p>{{Compat("javascript.builtins.Array.every")}}</p>
</div>
<h2 id="See_also">See also</h2>
<ul>
<li>{{jsxref("Array.prototype.forEach()")}}</li>
<li>{{jsxref("Array.prototype.some()")}}</li>
<li>{{jsxref("Array.prototype.find()")}}</li>
<li>{{jsxref("TypedArray.prototype.every()")}}</li>
</ul>
|