|
|
- <!DOCTYPE html>
- <html lang="en-US">
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width,initial-scale=1">
- <title>last() | collect.js</title>
- <meta name="description" content="Convenient and dependency free wrapper for working with arrays and objects.">
-
-
- <link rel="preload" href="/<REPO>/assets/css/0.styles.cf26012d.css" as="style"><link rel="preload" href="/<REPO>/assets/js/app.14e4c2ec.js" as="script"><link rel="preload" href="/<REPO>/assets/js/2.87b3604c.js" as="script"><link rel="preload" href="/<REPO>/assets/js/47.80ad8d7d.js" as="script"><link rel="prefetch" href="/<REPO>/assets/js/10.c61ccac3.js"><link rel="prefetch" href="/<REPO>/assets/js/100.f1cb0dd3.js"><link rel="prefetch" href="/<REPO>/assets/js/101.1db86157.js"><link rel="prefetch" href="/<REPO>/assets/js/102.2bf45f3c.js"><link rel="prefetch" href="/<REPO>/assets/js/103.04f11975.js"><link rel="prefetch" href="/<REPO>/assets/js/104.339b9c78.js"><link rel="prefetch" href="/<REPO>/assets/js/105.02d9eb06.js"><link rel="prefetch" href="/<REPO>/assets/js/106.99937062.js"><link rel="prefetch" href="/<REPO>/assets/js/107.aec6514a.js"><link rel="prefetch" href="/<REPO>/assets/js/108.46ef43a0.js"><link rel="prefetch" href="/<REPO>/assets/js/109.d03c0323.js"><link rel="prefetch" href="/<REPO>/assets/js/11.534c7609.js"><link rel="prefetch" href="/<REPO>/assets/js/110.1301ed6d.js"><link rel="prefetch" href="/<REPO>/assets/js/111.56c1eafe.js"><link rel="prefetch" href="/<REPO>/assets/js/112.876213a1.js"><link rel="prefetch" href="/<REPO>/assets/js/113.ba642269.js"><link rel="prefetch" href="/<REPO>/assets/js/114.4b773f17.js"><link rel="prefetch" href="/<REPO>/assets/js/115.995ef4ff.js"><link rel="prefetch" href="/<REPO>/assets/js/116.fb8e0edf.js"><link rel="prefetch" href="/<REPO>/assets/js/117.e91ef9f2.js"><link rel="prefetch" href="/<REPO>/assets/js/118.7e9c16e0.js"><link rel="prefetch" href="/<REPO>/assets/js/12.ebb0681e.js"><link rel="prefetch" href="/<REPO>/assets/js/13.b3e5d619.js"><link rel="prefetch" href="/<REPO>/assets/js/14.c957ed89.js"><link rel="prefetch" href="/<REPO>/assets/js/15.abbc647d.js"><link rel="prefetch" href="/<REPO>/assets/js/16.78c555be.js"><link rel="prefetch" href="/<REPO>/assets/js/17.7ab9a167.js"><link rel="prefetch" href="/<REPO>/assets/js/18.4b3c73bd.js"><link rel="prefetch" href="/<REPO>/assets/js/19.11a116d9.js"><link rel="prefetch" href="/<REPO>/assets/js/20.19feeb8a.js"><link rel="prefetch" href="/<REPO>/assets/js/21.5745e9aa.js"><link rel="prefetch" href="/<REPO>/assets/js/22.8910c1a3.js"><link rel="prefetch" href="/<REPO>/assets/js/23.fe5c23fe.js"><link rel="prefetch" href="/<REPO>/assets/js/24.6ed6d804.js"><link rel="prefetch" href="/<REPO>/assets/js/25.fd72bb93.js"><link rel="prefetch" href="/<REPO>/assets/js/26.6c22637d.js"><link rel="prefetch" href="/<REPO>/assets/js/27.ff2ad739.js"><link rel="prefetch" href="/<REPO>/assets/js/28.0aabe7f7.js"><link rel="prefetch" href="/<REPO>/assets/js/29.60968b26.js"><link rel="prefetch" href="/<REPO>/assets/js/3.20fa8bd4.js"><link rel="prefetch" href="/<REPO>/assets/js/30.e90c9cf7.js"><link rel="prefetch" href="/<REPO>/assets/js/31.d6437fab.js"><link rel="prefetch" href="/<REPO>/assets/js/32.f28f1d83.js"><link rel="prefetch" href="/<REPO>/assets/js/33.33e5481a.js"><link rel="prefetch" href="/<REPO>/assets/js/34.16e5f595.js"><link rel="prefetch" href="/<REPO>/assets/js/35.9338f581.js"><link rel="prefetch" href="/<REPO>/assets/js/36.4cc1614e.js"><link rel="prefetch" href="/<REPO>/assets/js/37.4c05651c.js"><link rel="prefetch" href="/<REPO>/assets/js/38.253a5089.js"><link rel="prefetch" href="/<REPO>/assets/js/39.13c74865.js"><link rel="prefetch" href="/<REPO>/assets/js/4.c843e0e7.js"><link rel="prefetch" href="/<REPO>/assets/js/40.9f440564.js"><link rel="prefetch" href="/<REPO>/assets/js/41.e3c7c1d9.js"><link rel="prefetch" href="/<REPO>/assets/js/42.1dbcc2a2.js"><link rel="prefetch" href="/<REPO>/assets/js/43.cd5ef633.js"><link rel="prefetch" href="/<REPO>/assets/js/44.eb672d2a.js"><link rel="prefetch" href="/<REPO>/assets/js/45.0bd75a5b.js"><link rel="prefetch" href="/<REPO>/assets/js/46.43143cbf.js"><link rel="prefetch" href="/<REPO>/assets/js/48.acbf3eb9.js"><link rel="prefetch" href="/<REPO>/assets/js/49.fcda4795.js"><link rel="prefetch" href="/<REPO>/assets/js/5.89d5d52d.js"><link rel="prefetch" href="/<REPO>/assets/js/50.c11d7fea.js
- <link rel="stylesheet" href="/<REPO>/assets/css/0.styles.cf26012d.css">
- </head>
- <body>
- <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/<REPO>/" class="home-link router-link-active"><!----> <span class="site-name">collect.js</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/<REPO>/" class="nav-link">Home</a></div><div class="nav-item"><a href="/<REPO>/installation.html" class="nav-link">Installation</a></div><div class="nav-item"><a href="/<REPO>/usage.html" class="nav-link">Usage</a></div><div class="nav-item"><a href="/<REPO>/api.html" class="nav-link">API</a></div><div class="nav-item"><a href="https://github.com/ecrmnn/collect.js" target="_blank" rel="noopener noreferrer" class="nav-link external">
- GitHub
- <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/<REPO>/" class="nav-link">Home</a></div><div class="nav-item"><a href="/<REPO>/installation.html" class="nav-link">Installation</a></div><div class="nav-item"><a href="/<REPO>/usage.html" class="nav-link">Usage</a></div><div class="nav-item"><a href="/<REPO>/api.html" class="nav-link">API</a></div><div class="nav-item"><a href="https://github.com/ecrmnn/collect.js" target="_blank" rel="noopener noreferrer" class="nav-link external">
- GitHub
- <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav> <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>Get started</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/<REPO>/installation.html" class="sidebar-link">Installation</a></li><li><a href="/<REPO>/usage.html" class="sidebar-link">Usage</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>API</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/<REPO>/api/all.html" class="sidebar-link">all()</a></li><li><a href="/<REPO>/api/average.html" class="sidebar-link">average()</a></li><li><a href="/<REPO>/api/avg.html" class="sidebar-link">avg()</a></li><li><a href="/<REPO>/api/chunk.html" class="sidebar-link">chunk()</a></li><li><a href="/<REPO>/api/collapse.html" class="sidebar-link">collapse()</a></li><li><a href="/<REPO>/api/combine.html" class="sidebar-link">combine()</a></li><li><a href="/<REPO>/api/concat.html" class="sidebar-link">concat()</a></li><li><a href="/<REPO>/api/contains.html" class="sidebar-link">contains()</a></li><li><a href="/<REPO>/api/count.html" class="sidebar-link">count()</a></li><li><a href="/<REPO>/api/countBy.html" class="sidebar-link">countBy()</a></li><li><a href="/<REPO>/api/crossJoin.html" class="sidebar-link">crossJoin()</a></li><li><a href="/<REPO>/api/dd.html" class="sidebar-link">dd()</a></li><li><a href="/<REPO>/api/diff.html" class="sidebar-link">diff()</a></li><li><a href="/<REPO>/api/diffAssoc.html" class="sidebar-link">diffAssoc()</a></li><li><a href="/<REPO>/api/diffKeys.html" class="sidebar-link">diffKeys()</a></li><li><a href="/<REPO>/api/dump.html" class="sidebar-link">dump()</a></li><li><a href="/<REPO>/api/duplicates.html" class="sidebar-link">duplicates()</a></li><li><a href="/<REPO>/api/each.html" class="sidebar-link">each()</a></li><li><a href="/<REPO>/api/eachSpread.html" class="sidebar-link">eachSpread()</a></li><li><a href="/<REPO>/api/every.html" class="sidebar-link">every()</a></li><li><a href="/<REPO>/api/except.html" class="sidebar-link">except()</a></li><li><a href="/<REPO>/api/filter.html" class="sidebar-link">filter()</a></li><li><a href="/<REPO>/api/first.html" class="sidebar-link">first()</a></li><li><a href="/<REPO>/api/firstWhere.html" class="sidebar-link">firstWhere()</a></li><li><a href="/<REPO>/api/flatMap.html" class="sidebar-link">flatMap()</a></li><li><a href="/<REPO>/api/flatten.html" class="sidebar-link">flatten()</a></li><li><a href="/<REPO>/api/flip.html" class="sidebar-link">flip()</a></li><li><a href="/<REPO>/api/forPage.html" class="sidebar-link">forPage()</a></li><li><a href="/<REPO>/api/forget.html" class="sidebar-link">forget()</a></li><li><a href="/<REPO>/api/get.html" class="sidebar-link">get()</a></li><li><a href="/<REPO>/api/groupBy.html" class="sidebar-link">groupBy()</a></li><li><a href="/<REPO>/api/has.html" class="sidebar-link">has()</a></li><li><a href="/<REPO>/api/implode.html" class="sidebar-link">implode()</a></li><li><a href="/<REPO>/api/intersect.html" class="sidebar-link">intersect()</a></li><li><a href="/<REPO>/api/intersectByKeys.html" class="sidebar-link">intersectByKeys()</a></li><li><a href="/<REPO>/api/isEmpty.html" class="sidebar-link">isEmpty()</a></li><li><a href="/<REPO>/api/isNotEmpty.html" class="sidebar-link">isNotEmpty()</a></li><li><a href="/<REPO>/api/join.htm
-
- <span class="token keyword">const</span> last <span class="token operator">=</span> collection<span class="token punctuation">.</span><span class="token function">last</span><span class="token punctuation">(</span><span class="token parameter">item</span> <span class="token operator">=></span> item <span class="token operator">></span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
-
- <span class="token comment">//=> 3</span>
- </code></pre></div><p>You may also call the last method with no arguments to get the last element in the collection. If the collection is empty, <code>null</code> is returned:</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token function">collect</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">last</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
-
- <span class="token comment">//=> 4</span>
- </code></pre></div><p><a href="https://github.com/ecrmnn/collect.js/blob/master/src/methods/last.js" target="_blank" rel="noopener noreferrer">View source on GitHub<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p></div> <footer class="page-edit"><!----> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
- ←
- <a href="/<REPO>/api/keys.html" class="prev">
- keys()
- </a></span> <span class="next"><a href="/<REPO>/api/macro.html">
- macro()
- </a>
- →
- </span></p></div> </main></div><div class="global-ui"></div></div>
- <script src="/<REPO>/assets/js/app.14e4c2ec.js" defer></script><script src="/<REPO>/assets/js/2.87b3604c.js" defer></script><script src="/<REPO>/assets/js/47.80ad8d7d.js" defer></script>
- </body>
- </html>
|