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

Mapの連想配列の最大値を取得するには、Math.max()を使います。
まず、Math.max()を呼び出します。
Math.max()の引数で、Mapの値をスプレッド構文を使って展開します。
Mapの値は、Mapからvalues()を呼び出して取得します。
const max = Math.max(...map.values())
上記のMath.max()は、values()を呼び出した連想配列の最大値を取得します。
使用例
const numbers = new Map([[ "one", 1], ["two", 2], ["three", 3], ["ten", 10], ["four", 4], ["five", 5 ]]);
const max = Math.max(...numbers.values())
console.log(max);
出力:
10
コメント