1.1 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	
			1.1 KiB
		
	
	
	
	
	
	
	
title, localeTitle
| title | localeTitle | 
|---|---|
| Math Max | 数学最大 | 
数学最大
Math.max()是一个函数,它返回作为参数传递的数值列表中的最大值。如果将非数字值作为参数传递, Math.max()将返回NaN 。
可以使用spread (...)或apply数值数组作为单个参数传递给Math.max() 。但是,当数组值的数量过高时,这些方法中的任何一个都会失败。
句法
Math.max(value1, value2, value3, ...); 
参数
数字或有限的数字数组。
回报价值
给定数值的最大值,如果任何给定值为非数字,则为NaN 。
例子
数字作为参数
Math.max(4, 13, 27, 0, -5); // returns 27 
无效的参数
Math.max(4, 13, 27, 'eight', -5); // returns NaN 
数组作为参数,使用Spread(...)
let numbers = [4, 13, 27, 0, -5]; 
 
 Math.max(...numbers); // returns 27 
数组作为参数,使用Apply
let numbers = [4, 13, 27, 0, -5]; 
 
 Math.max.apply(null, numbers); // returns 27