aboutsummaryrefslogtreecommitdiff
path: root/files/vi/web/javascript/reference/global_objects/array/flat
diff options
context:
space:
mode:
authorRyan Johnson <rjohnson@mozilla.com>2021-04-29 16:16:42 -0700
committerGitHub <noreply@github.com>2021-04-29 16:16:42 -0700
commit95aca4b4d8fa62815d4bd412fff1a364f842814a (patch)
tree5e57661720fe9058d5c7db637e764800b50f9060 /files/vi/web/javascript/reference/global_objects/array/flat
parentee3b1c87e3c8e72ca130943eed260ad642246581 (diff)
downloadtranslated-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/flat')
-rw-r--r--files/vi/web/javascript/reference/global_objects/array/flat/index.html179
1 files changed, 0 insertions, 179 deletions
diff --git a/files/vi/web/javascript/reference/global_objects/array/flat/index.html b/files/vi/web/javascript/reference/global_objects/array/flat/index.html
deleted file mode 100644
index 065a92a7a5..0000000000
--- a/files/vi/web/javascript/reference/global_objects/array/flat/index.html
+++ /dev/null
@@ -1,179 +0,0 @@
----
-title: Array.prototype.flat()
-slug: Web/JavaScript/Reference/Global_Objects/Array/flat
-tags:
- - Array
- - JavaScript
- - Method
- - Prototype
- - Reference
- - flat
-translation_of: Web/JavaScript/Reference/Global_Objects/Array/flat
----
-<div>{{JSRef}}</div>
-
-<div>Phương thức <code><strong>flat()</strong></code>  trả về một mảng mới. Trong đó, tất cả các phần tử của mảng con được gán ngược vào nó bằng  cách đệ quy lên đến độ sâu đã chỉ định.</div>
-
-
-
-<p>{{EmbedInteractiveExample("pages/js/array-flat.html")}}</p>
-
-
-
-<h2 id="Syntax">Syntax</h2>
-
-<pre class="syntaxbox notranslate"><var>var newArray = arr</var>.flat(<em>[depth]</em>);</pre>
-
-<h3 id="Parameters">Parameters</h3>
-
-<dl>
- <dt><code>depth</code> {{optional_inline}}</dt>
- <dd>Chỉ định độ sâu của mảng kết quả cuối cùng. Mặc định là 1</dd>
-</dl>
-
-<h3 id="Return_value">Return value</h3>
-
-<p>Một mảng mới với các phần tử của mảng con được nối với nó.</p>
-
-<h2 id="Alternatives">Alternatives</h2>
-
-<h3 id="reduce_and_concat">reduce and concat</h3>
-
-<pre class="brush: js notranslate">const arr = [1, 2, [3, 4]];
-
-// Trả về mảng chỉ có 1 level
-arr.flat();
-
-// Nó ngang với việc sử dụng reduce
-arr.reduce((acc, val) =&gt; acc.concat(val), []);
-// [1, 2, 3, 4]
-
-// hoặc decomposition syntax
-const flattened = arr =&gt; [].concat(...arr);
-</pre>
-
-<h3 id="reduce_concat_isArray_recursivity">reduce + concat + isArray + recursivity</h3>
-
-<pre class="brush: js notranslate">const arr = [1, 2, [3, 4, [5, 6]]];
-
-// ?Sử dụng reduce, concat và deep level
-function flatDeep(arr, d = 1) {
- return d &gt; 0 ? arr.reduce((acc, val) =&gt; acc.concat(Array.isArray(val) ? flatDeep(val, d - 1) : val), [])
- : arr.slice();
-};
-
-flatDeep(arr, Infinity);
-// [1, 2, 3, 4, 5, 6]
-</pre>
-
-<h3 id="Use_a_stack">Use a stack</h3>
-
-<pre class="brush: js notranslate">// Sử dụng stack để đệ quy không cần báo deep level
-
-function flatten(input) {
- const stack = [...input];
- const res = [];
- while(stack.length) {
- // Lấy gía trị ra khỏi stack
- const next = stack.pop();
- if(Array.isArray(next)) {
-  // Gán trở lại arry, không thay đổi giá trị của item đó
- stack.push(...next);
- } else {
- res.push(next);
- }
- }
- // Đảo ngược array để trả về đúng order ban đầu
- return res.reverse();
-}
-
-const arr = [1, 2, [3, 4, [5, 6]]];
-flatten(arr);
-// [1, 2, 3, 4, 5, 6]
-</pre>
-
-<h3 id="Use_Generator_function">Use Generator function</h3>
-
-<pre class="brush: js notranslate">function* flatten(array, depth) {
- if(depth === undefined) {
- depth = 1;
- }
- for(const item of array) {
- if(Array.isArray(item) &amp;&amp; depth &gt; 0) {
- yield* flatten(item, depth - 1);
- } else {
- yield item;
- }
- }
-}
-
-const arr = [1, 2, [3, 4, [5, 6]]];
-const flattened = [...flatten(arr, Infinity)];
-// [1, 2, 3, 4, 5, 6]
-</pre>
-
-<div class="hidden">
-<p>Please do not add polyfills on this article. For reference, please check: <a href="https://discourse.mozilla.org/t/mdn-rfc-001-mdn-wiki-pages-shouldnt-be-a-distributor-of-polyfills/24500">https://discourse.mozilla.org/t/mdn-rfc-001-mdn-wiki-pages-shouldnt-be-a-distributor-of-polyfills/24500</a></p>
-</div>
-
-<h2 id="Examples">Examples</h2>
-
-<h3 id="Flattening_nested_arrays">Flattening nested arrays</h3>
-
-<pre class="brush: js notranslate">const arr1 = [1, 2, [3, 4]];
-arr1.flat();
-// [1, 2, 3, 4]
-
-const arr2 = [1, 2, [3, 4, [5, 6]]];
-arr2.flat();
-// [1, 2, 3, 4, [5, 6]]
-
-const arr3 = [1, 2, [3, 4, [5, 6]]];
-arr3.flat(2);
-// [1, 2, 3, 4, 5, 6]
-
-const arr4 = [1, 2, [3, 4, [5, 6, [7, 8, [9, 10]]]]];
-arr4.flat(Infinity);
-// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
-</pre>
-
-<h3 id="Flattening_and_array_holes">Flattening and array holes</h3>
-
-<p>The flat method removes empty slots in arrays:</p>
-
-<pre class="brush: js notranslate">const arr5 = [1, 2, , 4, 5];
-arr5.flat();
-// [1, 2, 4, 5]
-</pre>
-
-<h2 id="Specifications">Specifications</h2>
-
-<table class="standard-table">
- <thead>
- <tr>
- <th scope="col">Specification</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>{{SpecName('ESDraft', '#sec-array.prototype.flat', 'Array.prototype.flat')}}</td>
- </tr>
- </tbody>
-</table>
-
-<h2 id="Browser_compatibility">Browser compatibility</h2>
-
-<div>
-
-
-<p>{{Compat("javascript.builtins.Array.flat")}}</p>
-</div>
-
-<h2 id="See_also">See also</h2>
-
-<ul>
- <li>{{jsxref("Array.prototype.flatMap()")}}</li>
- <li>{{jsxref("Array.prototype.map()")}}</li>
- <li>{{jsxref("Array.prototype.reduce()")}}</li>
- <li>{{jsxref("Array.prototype.concat()")}}</li>
-</ul>