diff options
Diffstat (limited to 'files/zh-tw/web/javascript/reference/global_objects/array')
-rw-r--r-- | files/zh-tw/web/javascript/reference/global_objects/array/length/index.html | 10 | ||||
-rw-r--r-- | files/zh-tw/web/javascript/reference/global_objects/array/slice/index.html | 14 |
2 files changed, 12 insertions, 12 deletions
diff --git a/files/zh-tw/web/javascript/reference/global_objects/array/length/index.html b/files/zh-tw/web/javascript/reference/global_objects/array/length/index.html index 453564d528..1b6497b07a 100644 --- a/files/zh-tw/web/javascript/reference/global_objects/array/length/index.html +++ b/files/zh-tw/web/javascript/reference/global_objects/array/length/index.html @@ -7,7 +7,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/length <p><code><strong>length</strong></code> 為<code>Array物件的屬性</code> ,可供設定或回傳該陣列實體中包含的元素個數。其值必為一大於零、32位元、且恆大於該陣列最大索引數的正整數。</p> -<pre class="brush: js notranslate">var items = ['shoes', 'shirts', 'socks', 'sweaters']; +<pre class="brush: js">var items = ['shoes', 'shirts', 'socks', 'sweaters']; items.length; // returns 4</pre> @@ -16,7 +16,7 @@ items.length; <p><code>length</code> 屬性的值必為一正整數,其值必介於 0 ~ 2<sup>32</sup> (不包含)之間.</p> -<pre class="brush: js notranslate">var namelistA = new Array(4294967296); //2<sup>32</sup><sup> = </sup>4294967296 +<pre class="brush: js">var namelistA = new Array(4294967296); //2<sup>32</sup><sup> = </sup>4294967296 var namelistC = new Array(-100) //負數 console.log(namelistA.length); //RangeError: Invalid array length @@ -32,7 +32,7 @@ console.log(namelistB.length); <p>你可以透過改變 <code>length</code> 屬性來改變陣列的長度。當你透過 <code>length</code> 屬性來增加陣列的長度時,陣列中實際的元素也會隨之增加。舉例來說,當你將 array.length 由 2 增加為3,則改動後該陣列即擁有3個元素,該新增的元素則會是一個不可迭代(non-iterable)的空槽(empty slot)。</p> -<pre class="notranslate">const arr = [1, 2]; +<pre>const arr = [1, 2]; console.log(arr); // [ 1, 2 ] @@ -62,7 +62,7 @@ arr.forEach(element => console.log(element)); // 空元素無法被迭代 <p>以下範例中, 陣列 <code>numbers</code> 透過 <code>length</code> 屬性進行迭代操作,並將其內容值加倍。</p> -<pre class="brush: js notranslate">var numbers = [1, 2, 3, 4, 5]; +<pre class="brush: js">var numbers = [1, 2, 3, 4, 5]; var length = numbers.length; for (var i = 0; i < length; i++) { numbers[i] *= 2; @@ -74,7 +74,7 @@ for (var i = 0; i < length; i++) { <p>以下範例中, 陣列 <code>numbers</code> 的長度若大於 3,則將其長度縮減至 3。</p> -<pre class="brush: js notranslate">var numbers = [1, 2, 3, 4, 5]; +<pre class="brush: js">var numbers = [1, 2, 3, 4, 5]; if (numbers.length > 3) { numbers.length = 3; diff --git a/files/zh-tw/web/javascript/reference/global_objects/array/slice/index.html b/files/zh-tw/web/javascript/reference/global_objects/array/slice/index.html index e9cb1fb02c..7079acee9d 100644 --- a/files/zh-tw/web/javascript/reference/global_objects/array/slice/index.html +++ b/files/zh-tw/web/javascript/reference/global_objects/array/slice/index.html @@ -19,7 +19,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/slice <h2 id="語法">語法</h2> -<pre class="syntaxbox notranslate"><var>arr</var>.slice(<em>[</em><var>begin[</var>, <var>end]]</var>) +<pre class="syntaxbox"><var>arr</var>.slice(<em>[</em><var>begin[</var>, <var>end]]</var>) </pre> <h3 id="參數">參數</h3> @@ -56,7 +56,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/slice <h3 id="Return_a_portion_of_an_existing_array">Return a portion of an existing array</h3> -<pre class="brush: js notranslate">var fruits = ['Banana', 'Orange', 'Lemon', 'Apple', 'Mango']; +<pre class="brush: js">var fruits = ['Banana', 'Orange', 'Lemon', 'Apple', 'Mango']; var citrus = fruits.slice(1, 3); // fruits contains ['Banana', 'Orange', 'Lemon', 'Apple', 'Mango'] @@ -67,7 +67,7 @@ var citrus = fruits.slice(1, 3); <p>In the following example, <code>slice</code> creates a new array, <code>newCar</code>, from <code>myCar</code>. Both include a reference to the object <code>myHonda</code>. When the color of <code>myHonda</code> is changed to purple, both arrays reflect the change.</p> -<pre class="brush: js notranslate">// Using slice, create newCar from myCar. +<pre class="brush: js">// Using slice, create newCar from myCar. var myHonda = { color: 'red', wheels: 4, engine: { cylinders: 4, size: 2.2 } }; var myCar = [myHonda, 2, 'cherry condition', 'purchased 1997']; var newCar = myCar.slice(0, 2); @@ -90,7 +90,7 @@ console.log('newCar[0].color = ' + newCar[0].color); <p>This script writes:</p> -<pre class="brush: js notranslate">myCar = [{color: 'red', wheels: 4, engine: {cylinders: 4, size: 2.2}}, 2, +<pre class="brush: js">myCar = [{color: 'red', wheels: 4, engine: {cylinders: 4, size: 2.2}}, 2, 'cherry condition', 'purchased 1997'] newCar = [{color: 'red', wheels: 4, engine: {cylinders: 4, size: 2.2}}, 2] myCar[0].color = red @@ -104,7 +104,7 @@ newCar[0].color = purple <p><code>slice</code> method can also be called to convert Array-like objects / collections to a new Array. You just bind the method to the object. The {{jsxref("Functions/arguments", "arguments")}} inside a function is an example of an 'array-like object'.</p> -<pre class="brush: js notranslate">function list() { +<pre class="brush: js">function list() { return Array.prototype.slice.call(arguments); } @@ -113,7 +113,7 @@ var list1 = list(1, 2, 3); // [1, 2, 3] <p>Binding can be done with the .<code>call</code> function of {{jsxref("Function.prototype")}} and it can also be reduced using <code>[].slice.call(arguments)</code> instead of <code>Array.prototype.slice.call</code>. Anyway, it can be simplified using {{jsxref("Function.prototype.bind", "bind")}}.</p> -<pre class="brush: js notranslate">var unboundSlice = Array.prototype.slice; +<pre class="brush: js">var unboundSlice = Array.prototype.slice; var slice = Function.prototype.call.bind(unboundSlice); function list() { @@ -127,7 +127,7 @@ var list1 = list(1, 2, 3); // [1, 2, 3] <p>Although host objects (such as DOM objects) are not required by spec to follow the Mozilla behavior when converted by <code>Array.prototype.slice</code> and IE < 9 does not do so, versions of IE starting with version 9 do allow this. “Shimming” it can allow reliable cross-browser behavior. As long as other modern browsers continue to support this ability, as currently do IE, Mozilla, Chrome, Safari, and Opera, developers reading (DOM-supporting) slice code relying on this shim will not be misled by the semantics; they can safely rely on the semantics to provide the now apparently <em>de facto</em> standard behavior. (The shim also fixes IE to work with the second argument of <code>slice()</code> being an explicit {{jsxref("null")}}/{{jsxref("undefined")}} value as earlier versions of IE also did not allow but all modern browsers, including IE >= 9, now do.)</p> -<pre class="brush: js notranslate">/** +<pre class="brush: js">/** * Shim for "fixing" IE's lack of support (IE < 9) for applying slice * on host objects like NamedNodeMap, NodeList, and HTMLCollection * (technically, since host objects have been implementation-dependent, |