TypeScript 配列の要素の最大値を取得するサンプル

環境
Windows 11 Pro 64bit
TypeScript 4.4.4

構文
const max = Math.max(…配列名)
配列の最大値を取得するには、 Math.max()を使います。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
const arr = [81, 12, 23, 10, 42, 52,]
const max = Math.max(...arr)
console.log(max)
const arr = [81, 12, 23, 10, 42, 52,] const max = Math.max(...arr) console.log(max)
const arr = [81, 12, 23, 10, 42, 52,]

const max = Math.max(...arr)

console.log(max)

実行結果
[LOG]: 81

TypeScript

Posted by arkgame