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.

24 lines
525 B

4 years ago
  1. # `mapToDictionary()`
  2. Run a dictionary map over the items.
  3. The callback should return an associative array with a single key/value pair.
  4. ```js
  5. const collection = collect([
  6. { id: 1, name: 'a' },
  7. { id: 2, name: 'b' },
  8. { id: 3, name: 'c' },
  9. { id: 4, name: 'b' },
  10. ]);
  11. const groups = collection.mapToDictionary(item => [item.name, item.id]);
  12. groups.all();
  13. // {
  14. // a: [1],
  15. // b: [2, 4],
  16. // c: [3],
  17. // }
  18. ```
  19. [View source on GitHub](https://github.com/ecrmnn/collect.js/blob/master/src/methods/mapToDictionary.js)