<article class=“article fmt article-content”><h2>slice介绍</h2><pre><code>Array.prototype.slice(startIndex, endIndex = Array.length - 1)</code></pre><p>用于将原数组依照<code>startIndex</code>和<code>endIndex</code>的地位进行提取,重点是<strong>该数组不会批改原数组</strong>,倡议优先思考应用。</p><pre><code class=“js”>const arr = [1, 2, 3]const nextArr = arr.slice(0, 1)console.log(‘arr’, arr)// [1, 2, 3]console.log(’nextArr’, nextArr)// [1]</code></pre><h2>some和every差别是什么?</h2><p>some<br/>承受一个函数,而后<code>some</code>会应用这个函数遍历整个数组,如果该函数至多有一次返回<code>true</code>,则<code>some</code>返回<code>true</code>,否则返回<code>false</code>。</p><p>every<br/>承受一个函数,而后<code>every</code>会应用这个函数遍历整个数组,如果该函数每次都返回<code>true</code>,则<code>every</code>返回<code>true</code>,否则返回<code>false</code>。</p><p>两者的差别<br/>some须要至多找到<strong>至多一次满足函数</strong>的数据项,才返回true。<br/>every须要数组的<strong>所有数据项都满足函数</strong>,才返回true。</p></article>