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.
 
 
 

117 lines
29 KiB

<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>groupBy() | 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/37.4c05651c.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/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"><link rel="prefetch" href="/<REPO>/assets/js/51.ac7ef5c5.js"><link rel="prefetch" href="/<REPO>/assets/js/52.20e7e008.js"><link rel="prefetch" href="/<REPO>/assets/js/53.3aebda95.js"><link rel="prefetch" href="/<REPO>/assets/js/54.32dd09e6.js"><link rel="prefetch" href="/<REPO>/assets/js/55.1390733c.js"><link rel="prefetch" href="/<REPO>/assets/js/56.323d9e4f.js"><link rel="prefetch" href="/<REPO>/assets/js/57.4f00873d.js"><link rel="prefetch" href="/<REPO>/assets/js/58.66742d06.js"><link rel="prefetch" href="/<REPO>/assets/js/59.6098fc41.js"><link rel="prefetch" href="/<REPO>/assets/js/6.d17194f0.js"><link rel="prefetch" href="/<REPO>/assets/js/60.ecf75149.js"><link rel="prefetch" href="/<REPO>/assets/js/61.06ecd66d.js"><link rel="prefetch" href="/<REPO>/assets/js/62.55af9c25.js"><link rel="prefetch" href="/<REPO>/assets/js/63.04e3a42d.js"><link rel="prefetch" href="/<REPO>/assets/js/64.434f9ebf.js"><link rel="prefetch" href="/<REPO>/assets/js/65.15c2d225.js"><link rel="prefetch" href="/<REPO>/assets/js/66.621171cc.js"><link rel="prefetch" href="/<REPO>/assets/js/67.b7ed4aa7.js"><link rel="prefetch" href="/<REPO>/assets/js/68.2fc54e06.js"><link rel="prefetch" href="/<REPO>/assets/js/69.8f1752a6.js"><link rel="prefetch" href="/<REPO>/assets/js/7.36d6745d.js"><link rel="prefetch" href="/<REPO>/assets/js/70.72b9acd8.js"><link rel="prefetch" href="/<REPO>/assets/js/71.4c6b2128.js"><link rel="prefetch" href="/<REPO>/assets/js/72.5797f6f2.js"><link rel="prefetch" href="/<REPO>/assets/js/73.c997a141.js"><link rel="prefetch" href="/<REPO>/assets/js/74.e2776c59.js"><link rel="prefetch" href="/<REPO>/assets/js/75.2073b6fa.js"><link rel="prefetch" href="/<REPO>/assets/js/76.8d950a11.js"><link rel="prefetch" href="/<REPO>/assets/js/77.af6025ee.js"><link rel="prefetch" href="/<REPO>/assets/js/78.c3e4ccf2.js"><link rel="prefetch" href="/<REPO>/assets/js/79.03b4b310.js"><link rel="prefetch" href="/<REPO>/assets/js/8.c71b046c.js"><link rel="prefetch" href="/<REPO>/assets/js/80.60847ab0.js"><link rel="prefetch" href="/<REPO>/assets/js/81.6a88a513.js"><link rel="prefetch" href="/<REPO>/assets/js/82.cd643697.js"><link rel="prefetch" href="/<REPO>/assets/js/83.1b506412.js"><link rel="prefetch" href="/<REPO>/assets/js/84.cb48c6e2.js"><link rel="prefetch" href="/<REPO>/assets/js/85.0077989d.js"><link rel="prefetch" href="/<REPO>/assets/js/86.b6139d33.js"><link rel="prefetch" href="/<REPO>/assets/js/87.3e61fc1b.js"><link rel="prefetch" href="/<REPO>/assets/js/88.2ddcbb58.js"><link rel="prefetch" href="/<REPO>/assets/js/89.eeb4b6e4.js"><link rel="prefetch" href="/<REPO>/assets/js/9.536986ca.js"><link rel="prefetch" href="/<REPO>/assets/js/90.13992b52.js"><link rel="prefetch" href="/<REPO>/assets/js/91.a0e54bab.js"><link rel="prefetch" href="/<REPO>/assets/js/92.35497373.js"><link rel="prefetch" href="/<REPO>/assets/js/93.28003955.js"><link rel="prefetch" href="/<REPO>/assets/js/94.f6992f44.js"><link rel="prefetch" href="/<REPO>/assets/js/95.585f327f.js"><link rel="prefetch" href="/<REPO>/assets/js/96.dc20cc78.js"><link rel="prefetch" href="/<REPO>/assets/js/97.c35b80e6.js"><link rel="prefetch" href="/<REPO>/assets/js/98.e29df611.js"><link rel="prefetch" href="/<REPO>/assets/js/99.90ebc36b.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="/&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">
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="/&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">
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="/&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="sidebar-link">get()</a></li><li><a href="/&lt;REPO&gt;/api/groupBy.html" class="active 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/join.html" class="sidebar-link">join()</a></li><li><a href="/&lt;REPO&gt;/api/keyBy.html" class="sidebar-link">keyBy()</a></li><li><a href="/&lt;REPO&gt;/api/keys.html" class="sidebar-link">keys()</a></li><li><a href="/&lt;REPO&gt;/api/last.html" class="sidebar-link">last()</a></li><li><a href="/&lt;REPO&gt;/api/macro.html" class="sidebar-link">macro()</a></li><li><a href="/&lt;REPO&gt;/api/make.html" class="sidebar-link">make()</a></li><li><a href="/&lt;REPO&gt;/api/map.html" class="sidebar-link">map()</a></li><li><a href="/&lt;REPO&gt;/api/mapInto.html" class="sidebar-link">mapInto()</a></li><li><a href="/&lt;REPO&gt;/api/mapSpread.html" class="sidebar-link">mapSpread()</a></li><li><a href="/&lt;REPO&gt;/api/mapToDictionary.html" class="sidebar-link">mapToDictionary()</a></li><li><a href="/&lt;REPO&gt;/api/mapToGroups.html" class="sidebar-link">mapToGroups()</a></li><li><a href="/&lt;REPO&gt;/api/mapWithKeys.html" class="sidebar-link">mapWithKeys()</a></li><li><a href="/&lt;REPO&gt;/api/max.html" class="sidebar-link">max()</a></li><li><a href="/&lt;REPO&gt;/api/median.html" class="sidebar-link">median()</a></li><li><a href="/&lt;REPO&gt;/api/merge.html" class="sidebar-link">merge()</a></li><li><a href="/&lt;REPO&gt;/api/mergeRecursive.html" class="sidebar-link">mergeRecursive()</a></li><li><a href="/&lt;REPO&gt;/api/min.html" class="sidebar-link">min()</a></li><li><a href="/&lt;REPO&gt;/api/mode.html" class="sidebar-link">mode()</a></li><li><a href="/&lt;REPO&gt;/api/nth.html" class="sidebar-link">nth()</a></li><li><a href="/&lt;REPO&gt;/api/only.html" class="sidebar-link">only()</a></li><li><a href="/&lt;REPO&gt;/api/pad.html" class="sidebar-link">pad()</a></li><li><a href="/&lt;REPO&gt;/api/partition.html" class="sidebar-link">partition()</a></li><li><a href="/&lt;REPO&gt;/api/pipe.html" class="sidebar-link">pipe()</a></li><li><a href="/&lt;REPO&gt;/api/pluck.html" class="sidebar-link">pluck()</a></li><li><a href="/&lt;REPO&gt;/api/pop.html" class="sidebar-link">pop()</a></li><li><a href="/&lt;REPO&gt;/api/prepend.html" class="sidebar-link">prepend()</a></li><li><a href="/&lt;REPO&gt;/api/pull.html" class="sidebar-link">pull()</a></li><li><a href="/&lt;REPO&gt;/api/push.html" class="sidebar-link">push()</a></li><li><a href="/&lt;REPO&gt;/api/put.html" class="sidebar-link">put()</a></li><li><a href="/&lt;REPO&gt;/api/random.html" class="sidebar-link">random()</a></li><li><a href="/&lt;REPO&gt;/api/reduce.html" class="sidebar-link">reduce()</a></li><li><a href="/&lt;REPO&gt;/api/reject.html" class="sidebar-link">reject()</a></li><li><a href="/&lt;REPO&gt;/api/replace.html" class="sidebar-link">replace()</a></li><li><a href="/&lt;REPO&gt;/api/replaceRecursive.html" class="sidebar-link">replaceRecursive()</a></li><li><a href="/&lt;REPO&gt;/api/reverse.html" class="sidebar-link">reverse()</a></li><li><a href="/&lt;REPO&gt;/api/search.html" class="sidebar-link">search()</a></li><li><a href="/&lt;REPO&gt;/api/shift.html" class="sidebar-link">shift()</a></li><li><a href="/&lt;REPO&gt;/api/shuffle.html" class="sidebar-link">shuffle()</a></li><li><a href="/&lt;REPO&gt;/api/slice.html" class="sidebar-link">slice()</a></li><li><a href="/&lt;REPO&gt;/api/some.html" class="sidebar-link">some()</a></li><li><a href="/&lt;REPO&gt;/api/sort.html" class="sidebar-link">sort()</a></li><li><a href="/&lt;REPO&gt;/api/sortBy.html" class="sidebar-link">sortBy()</a></li><li><a href="/&lt;REPO&gt;/api/sortByDesc.html" class="sidebar-link">sortByDesc()</a></li><li><a href="/&lt;REPO&gt;/api/sortKeys.html" class="sidebar-link">sortKeys()</a></li><li><a href="/&lt;REPO&gt;/api/sortKeysDesc.html" class="sidebar-link">sortKeysDesc()</a></li><li><a href="/&lt;REPO&gt;/api/splice.html" class="sidebar-link">splice()</a></li><li><a href="/&lt;REPO&gt;/api/split.html" class="sidebar-link">split()</a></li><li><a href="/&lt;REPO&gt;/api/sum.html" class="sidebar-link">sum()</a></li><li><a href="/&lt;REPO&gt;/api/take.html" class="sidebar-link">take()</a></li><li><a href="/&lt;REPO&gt;/api/tap.html" class="sidebar-link">tap()</a></li><li><a href="/&lt;REPO&gt;/api/times.html" class="sidebar-link">times()</a></li><li><a href="/&lt;REPO&gt;/api/toArray.html" class="sidebar-link">toArray()</a></li><li><a href="/&lt;REPO&gt;/api/toJson.html" class="sidebar-link">toJson()</a></li><li><a href="/&lt;REPO&gt;/api/transform.html" class="sidebar-link">transform()</a></li><li><a href="/&lt;REPO&gt;/api/union.html" class="sidebar-link">union()</a></li><li><a href="/&lt;REPO&gt;/api/unique.html" class="sidebar-link">unique()</a></li><li><a href="/&lt;REPO&gt;/api/unless.html" class="sidebar-link">unless()</a></li><li><a href="/&lt;REPO&gt;/api/unlessEmpty.html" class="sidebar-link">unlessEmpty()</a></li><li><a href="/&lt;REPO&gt;/api/unlessNotEmpty.html" class="sidebar-link">unlessNotEmpty()</a></li><li><a href="/&lt;REPO&gt;/api/unwrap.html" class="sidebar-link">unwrap()</a></li><li><a href="/&lt;REPO&gt;/api/values.html" class="sidebar-link">values()</a></li><li><a href="/&lt;REPO&gt;/api/when.html" class="sidebar-link">when()</a></li><li><a href="/&lt;REPO&gt;/api/whenEmpty.html" class="sidebar-link">whenEmpty()</a></li><li><a href="/&lt;REPO&gt;/api/whenNotEmpty.html" class="sidebar-link">whenNotEmpty()</a></li><li><a href="/&lt;REPO&gt;/api/where.html" class="sidebar-link">where()</a></li><li><a href="/&lt;REPO&gt;/api/whereBetween.html" class="sidebar-link">whereBetween()</a></li><li><a href="/&lt;REPO&gt;/api/whereIn.html" class="sidebar-link">whereIn()</a></li><li><a href="/&lt;REPO&gt;/api/whereInstanceOf.html" class="sidebar-link">whereInstanceOf()</a></li><li><a href="/&lt;REPO&gt;/api/whereNotBetween.html" class="sidebar-link">whereNotBetween()</a></li><li><a href="/&lt;REPO&gt;/api/whereNotIn.html" class="sidebar-link">whereNotIn()</a></li><li><a href="/&lt;REPO&gt;/api/wrap.html" class="sidebar-link">wrap()</a></li><li><a href="/&lt;REPO&gt;/api/zip.html" class="sidebar-link">zip()</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="groupby"><a href="#groupby" aria-hidden="true" class="header-anchor">#</a> <code>groupBy()</code></h1> <p>The groupBy method groups the collection's items by a given key:</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>
<span class="token punctuation">{</span>
product<span class="token punctuation">:</span> <span class="token string">&quot;Chair&quot;</span><span class="token punctuation">,</span>
manufacturer<span class="token punctuation">:</span> <span class="token string">&quot;IKEA&quot;</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">{</span>
product<span class="token punctuation">:</span> <span class="token string">&quot;Desk&quot;</span><span class="token punctuation">,</span>
manufacturer<span class="token punctuation">:</span> <span class="token string">&quot;IKEA&quot;</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">{</span>
product<span class="token punctuation">:</span> <span class="token string">&quot;Chair&quot;</span><span class="token punctuation">,</span>
manufacturer<span class="token punctuation">:</span> <span class="token string">&quot;Herman Miller&quot;</span>
<span class="token punctuation">}</span>
<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> grouped <span class="token operator">=</span> collection<span class="token punctuation">.</span><span class="token function">groupBy</span><span class="token punctuation">(</span><span class="token string">&quot;manufacturer&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
grouped<span class="token punctuation">.</span><span class="token function">all</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">//=&gt; {</span>
<span class="token comment">//=&gt; IKEA: [</span>
<span class="token comment">//=&gt; {</span>
<span class="token comment">//=&gt; id: 100,</span>
<span class="token comment">//=&gt; product: 'Chair',</span>
<span class="token comment">//=&gt; manufacturer: 'IKEA',</span>
<span class="token comment">//=&gt; price: '1490 NOK',</span>
<span class="token comment">//=&gt; },</span>
<span class="token comment">//=&gt; {</span>
<span class="token comment">//=&gt; id: 150,</span>
<span class="token comment">//=&gt; product: 'Desk',</span>
<span class="token comment">//=&gt; manufacturer: 'IKEA',</span>
<span class="token comment">//=&gt; price: '900 NOK',</span>
<span class="token comment">//=&gt; },</span>
<span class="token comment">//=&gt; ],</span>
<span class="token comment">//=&gt; 'Herman Miller': [</span>
<span class="token comment">//=&gt; {</span>
<span class="token comment">//=&gt; id: 200,</span>
<span class="token comment">//=&gt; product: 'Chair',</span>
<span class="token comment">//=&gt; manufacturer: 'Herman Miller',</span>
<span class="token comment">//=&gt; price: '9990 NOK',</span>
<span class="token comment">//=&gt; },</span>
<span class="token comment">//=&gt; ]</span>
<span class="token comment">//=&gt; }</span>
</code></pre></div><p>In addition to passing a string key, you may also pass a callback. The callback should return the value you wish to key the group by:</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>
<span class="token punctuation">{</span>
product<span class="token punctuation">:</span> <span class="token string">&quot;Chair&quot;</span><span class="token punctuation">,</span>
manufacturer<span class="token punctuation">:</span> <span class="token string">&quot;IKEA&quot;</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">{</span>
product<span class="token punctuation">:</span> <span class="token string">&quot;Desk&quot;</span><span class="token punctuation">,</span>
manufacturer<span class="token punctuation">:</span> <span class="token string">&quot;IKEA&quot;</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">{</span>
product<span class="token punctuation">:</span> <span class="token string">&quot;Chair&quot;</span><span class="token punctuation">,</span>
manufacturer<span class="token punctuation">:</span> <span class="token string">&quot;Herman Miller&quot;</span>
<span class="token punctuation">}</span>
<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> grouped <span class="token operator">=</span> collection<span class="token punctuation">.</span><span class="token function">groupBy</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">item<span class="token punctuation">,</span> key</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token keyword">return</span> item<span class="token punctuation">.</span>manufacturer<span class="token punctuation">.</span><span class="token function">substring</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
grouped<span class="token punctuation">.</span><span class="token function">all</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">//=&gt; {</span>
<span class="token comment">//=&gt; IKE: [</span>
<span class="token comment">//=&gt; {</span>
<span class="token comment">//=&gt; id: 100,</span>
<span class="token comment">//=&gt; product: 'Chair',</span>
<span class="token comment">//=&gt; manufacturer: 'IKEA',</span>
<span class="token comment">//=&gt; price: '1490 NOK',</span>
<span class="token comment">//=&gt; },</span>
<span class="token comment">//=&gt; {</span>
<span class="token comment">//=&gt; id: 150,</span>
<span class="token comment">//=&gt; product: 'Desk',</span>
<span class="token comment">//=&gt; manufacturer: 'IKEA',</span>
<span class="token comment">//=&gt; price: '900 NOK',</span>
<span class="token comment">//=&gt; },</span>
<span class="token comment">//=&gt; ],</span>
<span class="token comment">//=&gt; Her: [</span>
<span class="token comment">//=&gt; {</span>
<span class="token comment">//=&gt; id: 200,</span>
<span class="token comment">//=&gt; product: 'Chair',</span>
<span class="token comment">//=&gt; manufacturer: 'Herman Miller',</span>
<span class="token comment">//=&gt; price: '9990 NOK',</span>
<span class="token comment">//=&gt; },</span>
<span class="token comment">//=&gt; ]</span>
<span class="token comment">//=&gt; }</span>
</code></pre></div><p><a href="https://github.com/ecrmnn/collect.js/blob/master/src/methods/groupBy.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="/&lt;REPO&gt;/api/get.html" class="prev">
get()
</a></span> <span class="next"><a href="/&lt;REPO&gt;/api/has.html">
has()
</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/37.4c05651c.js" defer></script>
</body>
</html>