@@ -118,10 +118,6 @@ document.write(studentNames); // 田中,佐藤,鈴木,内藤
118118const numbers = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ];
119119```
120120
121- ``` javascript
122- const numbers = [- 3 , - 1 , 9 , - 10 , 3 , 7 , 6 , 1 , 0 , 5 ];
123- ```
124-
125121:::
126122
127123<Answer title = " 配列の要素の和" >
@@ -171,8 +167,6 @@ document.write(`配列の合計値は ${sum} です。`);
171167``` javascript
172168const array1 = [3 , 6 , 8 , 5 , 0 ];
173169const array2 = [- 8 , - 7 , - 3 , - 1 , - 5 ];
174- const array3 = [5986 , 7202 , 9347 , 3593 , 8166 , 662 , 2235 , 9323 , 2240 , 943 ];
175- const array4 = [- 878 , - 40 , - 324 , - 410 , - 592 , - 610 , - 880 , - 65 , - 423 , - 32 ];
176170```
177171
178172:::
@@ -192,8 +186,6 @@ const array4 = [-878, -40, -324, -410, -592, -610, -880, -65, -423, -32];
192186``` javascript
193187const array1 = [3 , 6 , 8 , 5 , 0 ];
194188const array2 = [- 8 , - 7 , - 3 , - 1 , - 5 ];
195- const array3 = [5986 , 7202 , 9347 , 3593 , 8166 , 662 , 2235 , 9323 , 2240 , 943 ];
196- const array4 = [- 878 , - 40 , - 324 , - 410 , - 592 , - 610 , - 880 , - 65 , - 423 , - 32 ];
197189
198190function findMaxNumber (numbers ) {
199191 if (numbers .length === 0 ) return ; // 空配列を除外
@@ -212,13 +204,6 @@ document.write(
212204document .write (
213205 ` <p>配列 [${ array2} ] の最大値は${ findMaxNumber (array2)} です。</p>` ,
214206);
215- document .write (
216- ` <p>配列 [${ array3} ] の最大値は${ findMaxNumber (array3)} です。</p>` ,
217- );
218- document .write (
219- ` <p>配列 [${ array4} ] の最大値は${ findMaxNumber (array4)} です。</p>` ,
220- );
221- document .write (` <p>空の配列の最大値は ${ findMaxNumber ([])} です。</p>` );
222207```
223208
224209:::danger
@@ -228,37 +213,3 @@ document.write(`<p>空の配列の最大値は ${findMaxNumber([])} です。</p
228213<ViewSource url = { import .meta .url } path = " _samples/array-max" />
229214
230215</Answer >
231-
232- { /* prettier-ignore */ }
233- { /* オブジェクトはまだ扱っていないためコメントアウト
234-
235- ## 配列とオブジェクト
236-
237- 配列はオブジェクトの一種です。しかしながら、JavaScript のオブジェクトとは、[オブジェクトの節](/docs/trial-session/object/)で扱ったように、プロパティ名とプロパティ値の組み合わせでした。
238-
239- 配列もこの原則に従って動作しています。次の図に示すように、配列とは、各要素のインデックスがプロパティ名になっているオブジェクトだと考えることができるのです。
240-
241- 
242-
243- 逆に、その他のオブジェクトも配列と同じように使用することができます。この記法を**ブラケット記法**と呼び、プログラムの動作に応じて使用したいプロパティを切り替えるのに役立ちます。
244-
245- ```javascript
246- const subject = "math"; // ここを変えると表示される教科が変わる
247- const scores = { math: 90, science: 80 };
248- document.write(`${subject} の点数は ${scores[subject]} です。`); // math の点数は 90 です。
249- ```
250-
251- :::tip[オブジェクトのプロパティ]
252-
253- オブジェクトのプロパティに数値は使用できません。それではなぜ、配列の場合は `studentNames[2]` のように記述できるのでしょうか。
254-
255- 答えは単純で、文字列に変換されているからです。このため、次のプログラムは全く問題なく動作します。
256-
257- ```javascript
258- const studentNames = ["田中", "佐藤", "鈴木"];
259- document.write(studentNames["0"]); // 田中
260- ```
261-
262- :::
263-
264- \*/ }
0 commit comments