最值
const arr = [5, 3, 8, 1, 6]; arr.sort((a, b) => b - a); const maxValue = arr[0]; console.log(maxValue); // 8const arr = [5, 3, 8, 1, 6]; arr.sort((a, b) => a - b); const minValue = arr[0]; console.log(minValue); // 1
const arr = [5, 3, 8, 1, 6]; const maxValue = Math.max(...arr); console.log(maxValue); // 8const arr = [5, 3, 8, 1, 6]; const minValue = Math.min(...arr); console.log(minValue); // 1
Last updated