Skip to main content
Version: 1.2.0

mapObjectKeys

Using

Function accepts an object and a transformation function, applies the transformation function to each key in the object, and returns a new object with the modified keys.

If value is not object type - function return undefined.

Demo - use JSON
mapObjectKeys(
,
)
{"it new package":"shegit","it new major-version":1}

Arguments

ArgumentTypeDescriptionExample
objectobjectObject for transform.{ some: "any" }
transformFnfunctionFunction for transform object.(value) => value.toUpperCase()

Returns

object — Mapped object.

Examples

const object1 = { firstName: 'John', lastName: 'Doe', age: 30 };
const transformFunction1 = (key) => key.toUpperCase();
mapObjectKeys(object1, transformFunction1);
// { FIRSTNAME: 'John', LASTNAME: 'Doe', AGE: 30 }

const object2 = { id: 1, name: 'Alice' };
const transformFunction2 = (key) => `user_${key}`;
mapObjectKeys(object2, transformFunction2);
// { user_id: 1, user_name: 'Alice' }

const object3 = { user: { id: 1, name: 'Alice' }, role: 'admin' };
const transformFunction3 = (key) => key.toUpperCase();
mapObjectKeys(object3, transformFunction3);
// {
// USER: { id: 1, name: 'Alice' },
// ROLE: 'admin',
// }

Resources

📦 Since:1.2.0
📦 Last updated:1.2.0
📦 Available in:1.3.0