diff options
| author | Ryan Johnson <rjohnson@mozilla.com> | 2021-04-29 16:16:42 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-29 16:16:42 -0700 |
| commit | 95aca4b4d8fa62815d4bd412fff1a364f842814a (patch) | |
| tree | 5e57661720fe9058d5c7db637e764800b50f9060 /files/vi/web/javascript/reference/global_objects/array/fill/index.html | |
| parent | ee3b1c87e3c8e72ca130943eed260ad642246581 (diff) | |
| download | translated-content-95aca4b4d8fa62815d4bd412fff1a364f842814a.tar.gz translated-content-95aca4b4d8fa62815d4bd412fff1a364f842814a.tar.bz2 translated-content-95aca4b4d8fa62815d4bd412fff1a364f842814a.zip | |
remove retired locales (#699)
Diffstat (limited to 'files/vi/web/javascript/reference/global_objects/array/fill/index.html')
| -rw-r--r-- | files/vi/web/javascript/reference/global_objects/array/fill/index.html | 149 |
1 files changed, 0 insertions, 149 deletions
diff --git a/files/vi/web/javascript/reference/global_objects/array/fill/index.html b/files/vi/web/javascript/reference/global_objects/array/fill/index.html deleted file mode 100644 index e7e8201c46..0000000000 --- a/files/vi/web/javascript/reference/global_objects/array/fill/index.html +++ /dev/null @@ -1,149 +0,0 @@ ---- -title: Array.prototype.fill() -slug: Web/JavaScript/Reference/Global_Objects/Array/fill -translation_of: Web/JavaScript/Reference/Global_Objects/Array/fill ---- -<div>{{JSRef}}</div> - -<p>Phương thức <code><strong>fill()</strong></code> điền (sửa đổi) tất cả các phần tử của một mảng từ một chỉ mục bắt đầu (số không mặc định) đến một chỉ mục kết thúc (độ dài mảng mặc định) với một giá trị tĩnh. Nó trả về mảng đã sửa đổi</p> - -<div>{{EmbedInteractiveExample("pages/js/array-fill.html")}}</div> - - - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox"><var>arr</var>.fill(<var>value[</var>, <var>start[<var>, <var>end]]</var>)</var></var> -</pre> - -<h3 id="Parameters">Parameters</h3> - -<dl> - <dt><code>value</code></dt> - <dd>Value to fill an array.</dd> - <dt><code>start</code> {{optional_inline}}</dt> - <dd>Start index, defaults to 0.</dd> - <dt><code>end</code> {{optional_inline}}</dt> - <dd>End index, defaults to <code>this.length</code>.</dd> -</dl> - -<h3 id="Return_value">Return value</h3> - -<p>The modified array.</p> - -<h2 id="Description">Description</h2> - -<p>The <code>fill</code> method takes up to three arguments <code>value</code>, <code>start</code> and <code>end</code>. The <code>start</code> and <code>end</code> arguments are optional with default values of <code>0</code> and the <code>length</code> of the <code>this</code> object.</p> - -<p>If <code>start</code> is negative, it is treated as <code>length+start</code> where <code>length</code> is the length of the array. If <code>end</code> is negative, it is treated as <code>length+end</code>.</p> - -<p><code>fill</code> is intentionally generic, it does not require that its <code>this</code> value be an Array object.</p> - -<p><code>fill</code> is a mutable method, it will change <code>this</code> object itself, and return it, not just return a copy of it.</p> - -<p>When <code>fill</code> gets passed an object, it will copy the reference and fill the array with references to that object.</p> - -<h2 id="Examples">Examples</h2> - -<pre class="brush: js">[1, 2, 3].fill(4); // [4, 4, 4] -[1, 2, 3].fill(4, 1); // [1, 4, 4] -[1, 2, 3].fill(4, 1, 2); // [1, 4, 3] -[1, 2, 3].fill(4, 1, 1); // [1, 2, 3] -[1, 2, 3].fill(4, 3, 3); // [1, 2, 3] -[1, 2, 3].fill(4, -3, -2); // [4, 2, 3] -[1, 2, 3].fill(4, NaN, NaN); // [1, 2, 3] -[1, 2, 3].fill(4, 3, 5); // [1, 2, 3] -Array(3).fill(4); // [4, 4, 4] -[].fill.call({ length: 3 }, 4); // {0: 4, 1: 4, 2: 4, length: 3} - -// Objects by reference. -var arr = Array(3).fill({}) // [{}, {}, {}]; -arr[0].hi = "hi"; // [{ hi: "hi" }, { hi: "hi" }, { hi: "hi" }] -</pre> - -<h2 id="Polyfill">Polyfill</h2> - -<pre class="brush: js">if (!Array.prototype.fill) { - Object.defineProperty(Array.prototype, 'fill', { - value: function(value) { - - // Steps 1-2. - if (this == null) { - throw new TypeError('this is null or not defined'); - } - - var O = Object(this); - - // Steps 3-5. - var len = O.length >>> 0; - - // Steps 6-7. - var start = arguments[1]; - var relativeStart = start >> 0; - - // Step 8. - var k = relativeStart < 0 ? - Math.max(len + relativeStart, 0) : - Math.min(relativeStart, len); - - // Steps 9-10. - var end = arguments[2]; - var relativeEnd = end === undefined ? - len : end >> 0; - - // Step 11. - var final = relativeEnd < 0 ? - Math.max(len + relativeEnd, 0) : - Math.min(relativeEnd, len); - - // Step 12. - while (k < final) { - O[k] = value; - k++; - } - - // Step 13. - return O; - } - }); -} -</pre> - -<p>If you need to support truly obsolete JavaScript engines that don't support <code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty">Object.defineProperty</a></code>, it's best not to polyfill <code>Array.prototype</code> methods at all, as you can't make them non-enumerable.</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-array.prototype.fill', 'Array.prototype.fill')}}</td> - <td>{{Spec2('ES2015')}}</td> - <td>Initial definition.</td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-array.prototype.fill', 'Array.prototype.fill')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td></td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibility">Browser compatibility</h2> - -<div> - - -<p>{{Compat("javascript.builtins.Array.fill")}}</p> -</div> - -<h2 id="See_also">See also</h2> - -<ul> - <li>{{jsxref("Array")}}</li> - <li>{{jsxref("TypedArray.prototype.fill()")}}</li> -</ul> |
