VDL Plugin SDK

mapValues

Import from @varavel/vdl-plugin-sdk/utils/objects.

function mapValues<T, K, V>(object, getNewValue): Record<K, V>;

Creates a new object with the same keys as the given object, but with values generated by running each own enumerable property of the object through the iteratee function.

Type Parameters

Type ParameterDescription
T extends objectThe type of the object.
K extends string | number | symbolThe type of the keys in the object.
VThe type of the new values generated by the iteratee function.

Parameters

ParameterTypeDescription
objectTThe object to iterate over.
getNewValue(value, key, object) => VThe function invoked per own enumerable property.

Returns

Record<K, V>

Returns the new mapped object.

Example

// Example usage:
const obj = { a: 1, b: 2 };
const result = mapValues(obj, (value) => value * 2);
console.log(result); // { a: 2, b: 4 }