diff options
Diffstat (limited to 'files/ru/web/javascript/reference/statements/for_each...in')
| -rw-r--r-- | files/ru/web/javascript/reference/statements/for_each...in/index.html | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/files/ru/web/javascript/reference/statements/for_each...in/index.html b/files/ru/web/javascript/reference/statements/for_each...in/index.html new file mode 100644 index 0000000000..c609f436c0 --- /dev/null +++ b/files/ru/web/javascript/reference/statements/for_each...in/index.html @@ -0,0 +1,126 @@ +--- +title: for each...in +slug: Web/JavaScript/Reference/Statements/for_each...in +translation_of: Archive/Web/JavaScript/for_each...in +--- +<div>{{jsSidebar("Statements")}}</div> + +<div class="warning"> +<p>Конструкция <code>for each...in</code> заявлена как "deprecated", как часть стандарта ECMA-357 (<a href="/en-US/docs/Archive/Web/E4X" title="/en-US/docs/E4X">E4X</a>). Поддержка E4X была удалена. Вместо <code>for each...in</code> рассмотрите использование <a href="/en-US/docs/Web/JavaScript/Reference/Statements/for...of">for...of</a>. (Пожалуйста обратите внимание: {{ bug("791343")}}.)<br> + <br> + <strong>Firefox теперь предупреждает об использовании <code>for each...in</code> и <code>for each...in</code> удаляется из ночных сборок. Пожалуйста, посмотрите <a href="/en-US/docs/Web/JavaScript/Reference/Errors/For-each-in_loops_are_deprecated">Warning: JavaScript 1.6's for-each-in loops are deprecated</a> для помощи в миграции.</strong></p> +</div> + +<p><strong>Выражение</strong> <code><strong>for each...in</strong></code> выполняет перебор свойств указанного объекта. Для каждого свойства выполняется указанный оператор.</p> + +<h2 id="Синтаксис">Синтаксис</h2> + +<pre class="syntaxbox">for each (<em>variable</em> in <em>object</em>) { + <em>statement</em> +}</pre> + +<dl> + <dt><code>variable</code></dt> + <dd>Variable to iterate over property values, optionally declared with the <code>var</code> keyword. This variable is local to the function, not to the loop.</dd> +</dl> + +<dl> + <dt><code>object</code></dt> + <dd>Object for which the properties are iterated.</dd> +</dl> + +<dl> + <dt><code>statement</code></dt> + <dd>A statement to execute for each property. To execute multiple statements within the loop, use a <a href="/en-US/docs/Web/JavaScript/Reference/Statements/block">block</a> statement (<code>{ ... }</code>) to group those statements.</dd> +</dl> + +<h2 id="Description">Description</h2> + +<p>Some built-in properties are not iterated over. These include all built-in methods of objects, e.g. <code>String</code>'s <code>indexOf</code> method. However, all user-defined properties are iterated over.</p> + +<h2 id="Examples">Examples</h2> + +<h3 id="Using_for_each...in">Using <code>for each...in</code></h3> + +<p><strong>Warning:</strong> Never use a loop like this on arrays. Only use it on objects. See <a href="/en-US/docs/Web/JavaScript/Reference/Statements/for...in"><code>for...in</code></a> for more details.</p> + +<p>The following snippet iterates over an object's properties, calculating their sum:</p> + +<pre class="brush:js">var sum = 0; +var obj = {prop1: 5, prop2: 13, prop3: 8}; + +for each (var item in obj) { + sum += item; +} + +console.log(sum); // logs "26", which is 5+13+8</pre> + +<h2 id="Specifications">Specifications</h2> + +<p>Not part of a current ECMA-262 specification. Implemented in JavaScript 1.6 and deprecated.</p> + +<h2 id="Браузерная_совместимость">Браузерная совместимость</h2> + +<p>{{CompatibilityTable}}</p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatNo}}</td> + <td>{{CompatGeckoDesktop("1.8")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Chrome for Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatGeckoMobile("1.0")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="Firefox_specific_note">Firefox specific note</h2> + +<ul> + <li><code>for each...in</code> удалён только из Nightly Firefox 53</li> +</ul> + +<h2 id="Смотрите_также">Смотрите также</h2> + +<ul> + <li><code><a href="/en-US/docs/Web/JavaScript/Reference/Statements/for...in">for...in</a></code> - аналогичный оператор по перебору <em>имён</em> свойств.</li> + <li><code><a href="/en-US/docs/Web/JavaScript/Reference/Statements/for...of">for...of</a></code> - аналогичный оператор, перебирающий <em>значения</em> свойств, но может быть использован только для перебираемых (iteratable) типов, so not for generic objects</li> + <li><code><a href="/en-US/docs/JavaScript/Reference/Statements/for">for</a></code></li> +</ul> |
