You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
26 KiB

4 years ago
  1. <!DOCTYPE html>
  2. <html lang="en-US">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width,initial-scale=1">
  6. <title>get() | collect.js</title>
  7. <meta name="description" content="Convenient and dependency free wrapper for working with arrays and objects.">
  8. <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/36.4cc1614e.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/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/47.80ad8d7d.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
  9. <link rel="stylesheet" href="/<REPO>/assets/css/0.styles.cf26012d.css">
  10. </head>
  11. <body>
  12. <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="/&lt;REPO&gt;/" 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="/&lt;REPO&gt;/" class="nav-link">Home</a></div><div class="nav-item"><a href="/&lt;REPO&gt;/installation.html" class="nav-link">Installation</a></div><div class="nav-item"><a href="/&lt;REPO&gt;/usage.html" class="nav-link">Usage</a></div><div class="nav-item"><a href="/&lt;REPO&gt;/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">
  13. GitHub
  14. <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="/&lt;REPO&gt;/" class="nav-link">Home</a></div><div class="nav-item"><a href="/&lt;REPO&gt;/installation.html" class="nav-link">Installation</a></div><div class="nav-item"><a href="/&lt;REPO&gt;/usage.html" class="nav-link">Usage</a></div><div class="nav-item"><a href="/&lt;REPO&gt;/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">
  15. GitHub
  16. <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="/&lt;REPO&gt;/installation.html" class="sidebar-link">Installation</a></li><li><a href="/&lt;REPO&gt;/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="/&lt;REPO&gt;/api/all.html" class="sidebar-link">all()</a></li><li><a href="/&lt;REPO&gt;/api/average.html" class="sidebar-link">average()</a></li><li><a href="/&lt;REPO&gt;/api/avg.html" class="sidebar-link">avg()</a></li><li><a href="/&lt;REPO&gt;/api/chunk.html" class="sidebar-link">chunk()</a></li><li><a href="/&lt;REPO&gt;/api/collapse.html" class="sidebar-link">collapse()</a></li><li><a href="/&lt;REPO&gt;/api/combine.html" class="sidebar-link">combine()</a></li><li><a href="/&lt;REPO&gt;/api/concat.html" class="sidebar-link">concat()</a></li><li><a href="/&lt;REPO&gt;/api/contains.html" class="sidebar-link">contains()</a></li><li><a href="/&lt;REPO&gt;/api/count.html" class="sidebar-link">count()</a></li><li><a href="/&lt;REPO&gt;/api/countBy.html" class="sidebar-link">countBy()</a></li><li><a href="/&lt;REPO&gt;/api/crossJoin.html" class="sidebar-link">crossJoin()</a></li><li><a href="/&lt;REPO&gt;/api/dd.html" class="sidebar-link">dd()</a></li><li><a href="/&lt;REPO&gt;/api/diff.html" class="sidebar-link">diff()</a></li><li><a href="/&lt;REPO&gt;/api/diffAssoc.html" class="sidebar-link">diffAssoc()</a></li><li><a href="/&lt;REPO&gt;/api/diffKeys.html" class="sidebar-link">diffKeys()</a></li><li><a href="/&lt;REPO&gt;/api/dump.html" class="sidebar-link">dump()</a></li><li><a href="/&lt;REPO&gt;/api/duplicates.html" class="sidebar-link">duplicates()</a></li><li><a href="/&lt;REPO&gt;/api/each.html" class="sidebar-link">each()</a></li><li><a href="/&lt;REPO&gt;/api/eachSpread.html" class="sidebar-link">eachSpread()</a></li><li><a href="/&lt;REPO&gt;/api/every.html" class="sidebar-link">every()</a></li><li><a href="/&lt;REPO&gt;/api/except.html" class="sidebar-link">except()</a></li><li><a href="/&lt;REPO&gt;/api/filter.html" class="sidebar-link">filter()</a></li><li><a href="/&lt;REPO&gt;/api/first.html" class="sidebar-link">first()</a></li><li><a href="/&lt;REPO&gt;/api/firstWhere.html" class="sidebar-link">firstWhere()</a></li><li><a href="/&lt;REPO&gt;/api/flatMap.html" class="sidebar-link">flatMap()</a></li><li><a href="/&lt;REPO&gt;/api/flatten.html" class="sidebar-link">flatten()</a></li><li><a href="/&lt;REPO&gt;/api/flip.html" class="sidebar-link">flip()</a></li><li><a href="/&lt;REPO&gt;/api/forPage.html" class="sidebar-link">forPage()</a></li><li><a href="/&lt;REPO&gt;/api/forget.html" class="sidebar-link">forget()</a></li><li><a href="/&lt;REPO&gt;/api/get.html" class="active sidebar-link">get()</a></li><li><a href="/&lt;REPO&gt;/api/groupBy.html" class="sidebar-link">groupBy()</a></li><li><a href="/&lt;REPO&gt;/api/has.html" class="sidebar-link">has()</a></li><li><a href="/&lt;REPO&gt;/api/implode.html" class="sidebar-link">implode()</a></li><li><a href="/&lt;REPO&gt;/api/intersect.html" class="sidebar-link">intersect()</a></li><li><a href="/&lt;REPO&gt;/api/intersectByKeys.html" class="sidebar-link">intersectByKeys()</a></li><li><a href="/&lt;REPO&gt;/api/isEmpty.html" class="sidebar-link">isEmpty()</a></li><li><a href="/&lt;REPO&gt;/api/isNotEmpty.html" class="sidebar-link">isNotEmpty()</a></li><li><a href="/&lt;REPO&gt;/api/j
  17. firstname<span class="token punctuation">:</span> <span class="token string">&quot;Chuck&quot;</span><span class="token punctuation">,</span>
  18. lastname<span class="token punctuation">:</span> <span class="token string">&quot;Norris&quot;</span>
  19. <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  20. collection<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string">&quot;lastname&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  21. <span class="token comment">//=&gt; Norris</span>
  22. collection<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string">&quot;middlename&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  23. <span class="token comment">//=&gt; null</span>
  24. </code></pre></div><div class="language-js extra-class"><pre class="language-js"><code><span class="token keyword">const</span> collection <span class="token operator">=</span> <span class="token function">collect</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token string">&quot;a&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;b&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;c&quot;</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  25. collection<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  26. <span class="token comment">//=&gt; b</span>
  27. </code></pre></div><p>You may optionally pass a default value as the second argument:</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token keyword">const</span> collection <span class="token operator">=</span> <span class="token function">collect</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  28. firstname<span class="token punctuation">:</span> <span class="token string">&quot;Chuck&quot;</span><span class="token punctuation">,</span>
  29. lastname<span class="token punctuation">:</span> <span class="token string">&quot;Norris&quot;</span>
  30. <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  31. collection<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string">&quot;middlename&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;default-value&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  32. <span class="token comment">//=&gt; default-value</span>
  33. </code></pre></div><p>You may even pass a callback as the default value. The result of the callback will be returned if the specified key does not exist:</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token keyword">const</span> collection <span class="token operator">=</span> <span class="token function">collect</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  34. firstname<span class="token punctuation">:</span> <span class="token string">&quot;Chuck&quot;</span><span class="token punctuation">,</span>
  35. lastname<span class="token punctuation">:</span> <span class="token string">&quot;Norris&quot;</span>
  36. <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  37. collection<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string">&quot;middlename&quot;</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token string">&quot;default-value&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  38. <span class="token comment">//=&gt; default-value</span>
  39. </code></pre></div><p><a href="https://github.com/ecrmnn/collect.js/blob/master/src/methods/get.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">
  40. <a href="/&lt;REPO&gt;/api/forget.html" class="prev">
  41. forget()
  42. </a></span> <span class="next"><a href="/&lt;REPO&gt;/api/groupBy.html">
  43. groupBy()
  44. </a>
  45. </span></p></div> </main></div><div class="global-ui"></div></div>
  46. <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/36.4cc1614e.js" defer></script>
  47. </body>
  48. </html>