diff options
author | Irvin <irvinfly@gmail.com> | 2022-02-16 02:02:49 +0800 |
---|---|---|
committer | Irvin <irvinfly@gmail.com> | 2022-02-16 02:35:54 +0800 |
commit | 01b0e12ba27b5069248fd09235e9a7143915ee30 (patch) | |
tree | 0e9edf538dc3fa3331e1dbb79239b58186765f86 /files/zh-cn/web/javascript/reference/global_objects/array/map | |
parent | 6ca84f1794af830ada9736d7289ce29aabb04ca3 (diff) | |
download | translated-content-01b0e12ba27b5069248fd09235e9a7143915ee30.tar.gz translated-content-01b0e12ba27b5069248fd09235e9a7143915ee30.tar.bz2 translated-content-01b0e12ba27b5069248fd09235e9a7143915ee30.zip |
remove `notranslate` class in zh-CN
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/array/map')
-rw-r--r-- | files/zh-cn/web/javascript/reference/global_objects/array/map/index.html | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/array/map/index.html b/files/zh-cn/web/javascript/reference/global_objects/array/map/index.html index b00ce5df07..1517622c81 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/array/map/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/array/map/index.html @@ -20,7 +20,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/map <h2 id="Syntax" name="Syntax">语法</h2> -<pre class="notranslate"><var>var new_array = arr</var>.map(function <var>callback(currentValue[, index[, array]]) { +<pre><var>var new_array = arr</var>.map(function <var>callback(currentValue[, index[, array]]) { // Return element for new_array </var> <var>}</var>[, <var>thisArg</var>])</pre> @@ -68,7 +68,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/map <p>下面的代码创建了一个新数组,值为原数组中对应数字的平方根。</p> -<pre class="brush: js notranslate">var numbers = [1, 4, 9]; +<pre class="brush: js">var numbers = [1, 4, 9]; var roots = numbers.map(Math.sqrt); // roots的值为[1, 2, 3], numbers的值仍为[1, 4, 9]</pre> @@ -76,7 +76,7 @@ var roots = numbers.map(Math.sqrt); <p>以下代码使用一个包含对象的数组来重新创建一个格式化后的数组。</p> -<pre class="brush: js notranslate">var kvArray = [{key: 1, value: 10}, +<pre class="brush: js">var kvArray = [{key: 1, value: 10}, {key: 2, value: 20}, {key: 3, value: 30}]; @@ -98,7 +98,7 @@ var reformattedArray = kvArray.map(function(obj) { <p>下面的代码表示了当函数需要一个参数时map的工作方式。当map循环遍历原始数组时,这个参数会自动被分配成数组中对应的每个元素。</p> -<pre class="brush: js notranslate">var numbers = [1, 4, 9]; +<pre class="brush: js">var numbers = [1, 4, 9]; var doubles = numbers.map(function(num) { return num * 2; }); @@ -110,7 +110,7 @@ var doubles = numbers.map(function(num) { <p>下面的例子演示如何在一个 {{jsxref("String")}} 上使用 map 方法获取字符串中每个字符所对应的 ASCII 码组成的数组:</p> -<pre class="brush: js notranslate">var map = Array.prototype.map +<pre class="brush: js">var map = Array.prototype.map var a = map.call("Hello World", function(x) { return x.charCodeAt(0); }) @@ -121,7 +121,7 @@ var a = map.call("Hello World", function(x) { <p>下面代码展示了如何去遍历用 <code>querySelectorAll </code>得到的动态对象集合。在这里,我们获得了文档里所有选中的选项,并将其打印:</p> -<pre class="brush: js notranslate">var elems = document.querySelectorAll('select option:checked'); +<pre class="brush: js">var elems = document.querySelectorAll('select option:checked'); var values = Array.prototype.map.call(elems, function(obj) { return obj.value; }); @@ -135,7 +135,7 @@ var values = Array.prototype.map.call(elems, function(obj) { <p>考虑下例:</p> -<pre class="notranslate"><code>["1", "2", "3"].map(parseInt);</code></pre> +<pre><code>["1", "2", "3"].map(parseInt);</code></pre> <p>我们期望输出 <code>[1, 2, 3]</code>, 而实际结果是 <code>[1, NaN, NaN]</code>.</p> @@ -149,14 +149,14 @@ var values = Array.prototype.map.call(elems, function(obj) { <p>第三个参数被parseInt忽视了, <u>but not the second one</u>, 但不是第二个。因此可能出现混淆。下面是迭代步骤的简明示例:</p> -<pre class="notranslate"><code>// parseInt(string, radix) -> map(parseInt(value, index)) +<pre><code>// parseInt(string, radix) -> map(parseInt(value, index)) /* first iteration (index is 0): */ parseInt("1", 0); // 1 /* second iteration (index is 1): */ parseInt("2", 1); // NaN /* third iteration (index is 2): */ parseInt("3", 2); // NaN</code></pre> <p>下面让我们来讨论解决方案:</p> -<pre class="notranslate"><code>function returnInt(element) { +<pre><code>function returnInt(element) { return parseInt(element, 10); } @@ -176,7 +176,7 @@ var values = Array.prototype.map.call(elems, function(obj) { <p>一个map方法调用 parseInt 作为一个参数的等效输出运行如下:</p> -<pre class="notranslate"><code>var xs = ['10', '10', '10']; +<pre><code>var xs = ['10', '10', '10']; xs = xs.map(parseInt); @@ -187,7 +187,7 @@ console.log(xs); // 输出结果为</code>(3) [10, NaN, 2]<code> <p>当返回undefined 或没有返回任何内容时:</p> -<pre class="notranslate"><code>var numbers = [1, 2, 3, 4]; +<pre><code>var numbers = [1, 2, 3, 4]; var filteredNumbers = numbers.map(function(num, index) { if(index < 3) { return num; @@ -201,7 +201,7 @@ var filteredNumbers = numbers.map(function(num, index) { <p><code>map</code> was added to the ECMA-262 standard in the 5th edition; as such it may not be present in all implementations of the standard. You can work around this by inserting the following code at the beginning of your scripts, allowing use of <code>map</code> in implementations which do not natively support it. This algorithm is exactly the one specified in ECMA-262, 5th edition, assuming {{jsxref("Object")}}, {{jsxref("TypeError")}}, and {{jsxref("Array")}} have their original values and that <code>callback.call</code> evaluates to the original value of <code>{{jsxref("Function.prototype.call")}}</code>.</p> -<pre class="notranslate"><code>// Production steps of ECMA-262, Edition 5, 15.4.4.19 +<pre><code>// Production steps of ECMA-262, Edition 5, 15.4.4.19 // Reference: http://es5.github.io/#x15.4.4.19 if (!Array.prototype.map) { |