This commit is contained in:
2022-04-07 18:09:31 +05:30
parent 36ea86d8e6
commit 1c779ef816
14095 changed files with 1769361 additions and 47 deletions
+22
View File
@@ -0,0 +1,22 @@
# `mapToGroups()`
The mapToGroups method iterates through the collection and passes each value to the given callback:
```js
const collection = collect([
{ id: 1, name: 'A' },
{ id: 2, name: 'B' },
{ id: 3, name: 'C' },
{ id: 4, name: 'B' },
]);
const groups = collection.mapToGroups((item, key) => [item.name, item.id]);
// {
// A: [1],
// B: [2, 4],
// C: [3],
// }
```
[View source on GitHub](https://github.com/ecrmnn/collect.js/blob/master/src/methods/mapToGroups.js)