mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
17 lines
387 B
JavaScript
17 lines
387 B
JavaScript
//#region src/object/pick.ts
|
|
/**
|
|
* Creates a new object with only the specified keys.
|
|
*
|
|
* @example
|
|
* const obj = { a: 1, b: 2, c: 3 };
|
|
* pick(obj, ['a', 'c']); // { a: 1, c: 3 }
|
|
*/
|
|
function pick(obj, keys) {
|
|
const result = {};
|
|
for (const key of keys) if (Object.hasOwn(obj, key)) result[key] = obj[key];
|
|
return result;
|
|
}
|
|
//#endregion
|
|
export { pick };
|
|
|
|
//# sourceMappingURL=pick.js.map
|