![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/clinic.corals.io/node_modules/collect.js/docs/api/ |
# `mapWithKeys()` The mapWithKeys method iterates through the collection and passes each value to the given callback. The callback should return an array where the first element represents the key and the second element represents the value pair: ```js const collection = collect([ { name: 'John', department: 'Sales', email: '[email protected]', }, { name: 'Jane', department: 'Marketing', email: '[email protected]', }, ]); const keyed = collection.mapWithKeys(item => [item.email, item.name]); keyed.all(); // { // '[email protected]': 'John', // '[email protected]': 'Jane', // } ``` [View source on GitHub](https://github.com/ecrmnn/collect.js/blob/master/src/methods/mapWithKeys.js)