Objects.map()
Syntax
function map<T extends object, U>(object: T, callback: (value: T[typeof key], key: keyof T) => U): MappedType<T, U>
Creates a new object from an existing one by mapping all keys with a transform function.
Parameters | |
object
|
The object to map. |
callback
|
A callback function that is called once for each enumerable key in the object and receives the value behind the key and the key itself as arguments. |
Example
import { Objects } from 'potence';
const colors = {
red: 0xff0000,
yellow: 0xffff00,
green: 0x00ff00,
blue: 0x0000ff,
purple: 0xff00ff,
cyan: 0x00ffff
};
Objects.map(colors, color => color.toString(16).padStart(6, '0'));
// returns:
// {
// red: 'ff0000',
// yellow: 'ffff00',
// green: '00ff00',
// blue: '0000ff',
// purple: 'ff00ff',
// cyan: '00ffff'
// }
Remarks
This function is analogous to
Array.prototype.map()
.
See also
Objects.filter()
.