mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2026-02-28 18:11:29 +08:00
语法高亮,滚动条美化,设置页面调整
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<div></div>
|
||||
<p><code><strong>Math.max()</strong></code> 函数返回一组数中的最大值。</p>
|
||||
<h2 id="Syntax" name="Syntax">语法</h2>
|
||||
<pre class="syntaxbox"><code>Math.max(<em>value1</em>[,<em>value2</em>, ...]) </code></pre>
|
||||
<pre><code class="language-javascript"><code>Math.max(<em>value1</em>[,<em>value2</em>, ...]) </code></code></pre>
|
||||
<h3 id="Parameters" name="Parameters">参数</h3>
|
||||
<dl>
|
||||
<dt><code>value1, value2, ...</code></dt>
|
||||
@@ -16,19 +16,19 @@
|
||||
<p>如果有任一参数不能被转换为数值,则结果为 <a href="Reference/Global_Objects/NaN" title="全局属性 NaN 的值表示不是一个数字(Not-A-Number)。"><code>NaN</code></a>。</p>
|
||||
<h2 id="Examples" name="Examples">示例</h2>
|
||||
<h3 id="Example:_Using_Math.max" name="Example:_Using_Math.max">使用 <code>Math.max()</code></h3>
|
||||
<pre class="brush: js">Math.max(10, 20); // 20
|
||||
<pre><code class="language-javascript">Math.max(10, 20); // 20
|
||||
Math.max(-10, -20); // -10
|
||||
Math.max(-10, 20); // 20
|
||||
</pre>
|
||||
</code></pre>
|
||||
<p>下面的方法使用 <a href="Reference/Global_Objects/Function/apply" title="apply() 方法调用一个具有给定this值的函数,以及作为一个数组(或类似数组对象)提供的参数。"><code>apply</code></a> 方法寻找一个数值数组中的最大元素。<code>getMaxOfArray([1,2,3])</code> 等价于 <code>Math.max(1, 2, 3)</code>,但是你可以使用 <code>getMaxOfArray</code> ()作用于任意长度的数组上。</p>
|
||||
<pre class="brush:js">function getMaxOfArray(numArray) {
|
||||
<pre><code class="language-js">function getMaxOfArray(numArray) {
|
||||
return Math.max.apply(null, numArray);
|
||||
}
|
||||
</pre>
|
||||
</code></pre>
|
||||
<p>或者通过使用最新的扩展语句<a href="Reference/Operators/Spread_operator" title="REDIRECT Spread syntax"><code>spread operator</code></a>,获得数组中的最大值变得更容易。</p>
|
||||
<pre class="brush: js">var arr = [1, 2, 3];
|
||||
<pre><code class="language-javascript">var arr = [1, 2, 3];
|
||||
var max = Math.max(...arr);
|
||||
</pre>
|
||||
</code></pre>
|
||||
<p> </p>
|
||||
<h2 id="规范">规范</h2>
|
||||
<table class="standard-table">
|
||||
|
||||
Reference in New Issue
Block a user