The property key type expected to exist on the object.
The value to validate.
Required own property keys.
OptionalincludeHidden: booleanWhether to include non-enumerable and symbol keys.
true if all specified keys exist on the object.
This function checks whether every key in the provided keys list
exists as an own property on the target object.
It does not require the object to have exactly the same keys; additional properties are allowed.
By default, only enumerable string keys are checked.
When includeHidden is enabled, all own property keys are included,
including non-enumerable and symbol keys.
Arrays are treated as objects and are therefore supported.
When validating arrays:
Object.keys() returns enumerable index keys ('0', '1', ...)Reflect.ownKeys() additionally includes non-enumerable own keys
such as 'length'This means enabling includeHidden may require including 'length'
in the expected key list for arrays. See example code below:
hasKeys([], ['length']); // false
hasKeys([], ['length'], true); // true
isRecordOf for value validation.Basic key validation:
const user = { id: 1, name: 'Alice' };
hasKeys(user, ['id', 'name']); // true
// Add new property to user
user.email = 'alice@example.com';
if (hasKeys(user, ['email'])) {
// Property `email` can be used here
}
Missing keys:
hasKeys(
{ id: 1 },
['id', 'name']
); // false
Extra keys are allowed:
hasKeys(
{ id: 1, name: 'Alice', active: true },
['id']
); // true
Symbol keys:
const key = Symbol('token');
hasKeys(
{ [key]: 'abc' },
[key],
true
); // true
Determines whether the provided value is an object containing all specified own property keys.