Objects.pick()
Syntax
function pick<T extends object, Keys extends keyof T>(object: T, ...which: Keys[]): Pick<T, Keys>
Creates a new object from an existing one with only a set of keys included.
Parameters | |
object
|
The object to pick keys from. |
which
Rest
|
The keys to include in the new object. |
Example
import { Objects } from 'potence';
const colors = {
red: 0xff0000,
yellow: 0xffff00,
green: 0x00ff00,
blue: 0x0000ff,
purple: 0xff00ff,
cyan: 0x00ffff
};
Objects.pick(colors, 'blue', 'cyan');
// returns:
// {
// blue: 0x0000ff,
// cyan: 0x00ffff
// }
Remarks
This function is analogous to TypeScript’s
Pick<T>
.
This function uses
Objects.filter()
internally. If you wish to filter by value, you may want to use
Objects.filter()
directly.
See also
Objects.omit()
.