reserveKeys
reserveKeys(obj, keys)
reserveKeys(obj, keys)
Creates a new object containing only the specified keys from the original input object. It filters out keys that are not included in the specified array and returns a new object with the reserved keys.
Arguments
obj
(Record<string, any>
): The input object to reserve keys from.keys
(string[]
): The array of keys to reserve in the new object.
Returns
Record<string, any>
: A new object containing only the specified keys.
Example
Usage
Notes
The
reserveKeys
function creates a new object containing only the specified keys from the input object.It preserves the original object and returns a new object with the selected key-value pairs.
This function is useful for creating a subset of an object containing only the necessary keys for specific use cases.
Last updated
Was this helpful?