mapKeys
Import from @varavel/vdl-plugin-sdk/utils/objects.
function mapKeys<T, K>(object, getNewKey): Record<K, T[keyof T]>;
Creates a new object with the same values as the given object, but with keys generated by running each own enumerable property of the object through the iteratee function.
Type Parameters
| Type Parameter | Description |
|---|---|
T extends Record<PropertyKey, any> | The type of the object. |
K extends PropertyKey | The type of the new keys generated by the iteratee function. |
Parameters
| Parameter | Type | Description |
|---|---|---|
object | T | The object to iterate over. |
getNewKey | (value, key, object) => K | The function invoked per own enumerable property. |
Returns
Record<K, T[keyof T]>
Returns the new mapped object.
Example
// Example usage:
const obj = { a: 1, b: 2 };
const result = mapKeys(obj, (value, key) => key + value);
console.log(result); // { a1: 1, b2: 2 }