mapify
Convert an array to a map
113 bytes
Usage
The mapify
function converts an array into a Map
object, allowing you to specify how keys and values are derived from each array item.
Parameters
array
: The input array to be converted into a Map.getKey
: A function that determines the key for each item in the array. It receives two arguments:item
: The current array item.index
: The index of the current item in the array.
getValue
(optional): A function that determines the value for each item in the array. If not provided, the original array item is used as the value. It also receives two arguments:item
: The current array item.index
: The index of the current item in the array.
Return Value
Returns a new Map
object where keys and values are derived from the input array using the provided mapping functions.