どうも、ちょげ(@chogetarou)です。
配列(Array)の最大値を取得する方法を紹介します。
方法

配列(Array)の最大値を取得するには、Math.max()を使います。
まず、Math.max()を呼び出します。
そして、Math.max(...array)
のように、Math.max()の引数に「…」と配列名を指定します。
let max = Math.max(...array);
上記のMath.max()は、「…」の右辺に指定した配列の最大値を返します。
使用例
let numbers = [1, 2, 3, 4, 5];
let max = Math.max(...numbers);
console.log(max);
出力:
5
コメント